I need to get data from checkboxes in a group box

get data from checkboxes in a group box

Page 1 of 1

3 Replies - 6028 Views - Last Post: 09 December 2010 - 11:46 PM Rate Topic: -----

#1 schmartyo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-December 10

I need to get data from checkboxes in a group box

Posted 09 December 2010 - 08:34 PM

Hey There Everybody,

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'


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!

Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: I need to get data from checkboxes in a group box

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9381
  • View blog
  • Posts: 35,226
  • Joined: 12-June 08

Re: I need to get data from checkboxes in a group box

Posted 09 December 2010 - 09:36 PM

You have your defined list of checkboxes, right? Why not just call each one, verify they are checked or not, increment your counter based on that, and get the 'text' names at the same time?
Was This Post Helpful? 1
  • +
  • -

#3 mavarazo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 37
  • View blog
  • Posts: 182
  • Joined: 25-October 10

Re: I need to get data from checkboxes in a group box

Posted 09 December 2010 - 11:41 PM

I think your foreach-Statement is wrong:

foreach (CheckBox check in groupBox_PIZZA_TOPPINGS)...


I can't check it, but with that it should work
foreach (CheckBox check in groupBox_PIZZA_TOPPINGS.Controls)...

Was This Post Helpful? 1
  • +
  • -

#4 schmartyo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-December 10

Re: I need to get data from checkboxes in a group box

Posted 09 December 2010 - 11:46 PM

All right, sounds good. Thanks!

Super cool, Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1