Friday, January 31, 2014

How can I put checkboxes into an array and use FOR LOOP to add value to a total when a user check the box

If you are using Windows Forms and all of the checkboxes are on a single form, you can loop over the form's controls collection and when you come across a checkbox, do something (i.e. add a price to the total).



foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(CheckBox))
{
//do something here
}
}

Once identified as a checkbox, a switch statement could be used to determine which checkbox and add an associated price.




- Brady My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!


No comments:

Post a Comment