I'm new to posting. Hope I'm doing this right.
I'm also new to C#. I'm trying to get data from checkboxes
inside a groupbox with a foreach loop. (see attached .jpg)
I need to get the number of boxes checked as well as the
string text associated with the checked box.
Here's my method.
//gets toppings from groupBox_PIZZA_TOPPINGS
public void getToppingsMethod()
{
numberOfToppings = 0;
toppingsAccumulator = "";
foreach (CheckBox check in groupBox_PIZZA_TOPPINGS)
{
if (check.Checked)
{
toppingsAccumulator = toppingsAccumulator + "\n" + check.Text;
}
numberOfToppings++;
}//closes foreach
}//closes getToppings Method
It's not working. Here's the error it shows;
Quote
foreach statement cannot operate on variables of type
'System.Windows.Forms.GroupBox' because 'System.Windows.Forms.GroupBox'
does not contain a public definition for 'GetEnumerator'
'System.Windows.Forms.GroupBox' because 'System.Windows.Forms.GroupBox'
does not contain a public definition for 'GetEnumerator'
It worked with radio buttons, I assumed it would work with checkboxes.
I searched the forums and found a similar post but couldn't
get the replied solution to work.
Any Suggestions?
Thank You!

New Topic/Question
Reply




MultiQuote






|