Counting and accessing checked checkboxes

0

I need to count checked checkboxes that are in a panel and are horizontal. It's Windows form, C #. I could not format a listbox for horizontal, so it's in a panel myself. But I would like to count them and access them with a bond. I tried concatenating the names that are in sequence, I tried via code, also without success. Anyone have any suggestions?

    
asked by anonymous 04.06.2015 / 22:08

1 answer

2

The fact that ChckBox's is in a Dashboard will make it easier to count in a loop. The Dashboard object maintains a list of Control objects that are in the "inside" of the Controls property. You just have to go through this list and, when you find a CheckBox , check if it is checked and count them.

private int getCheckedCount()
{
    int count = 0;
    foreach (Control control in panel1.Controls)
    {
        if (control is CheckBox) 
        {
            if(control.Checked) count++;
        }
    }
    return count;
}  
    
04.06.2015 / 22:59