Check Boxes

Is it THAT hard?

In VB6 I used arrays to check which checkboxes were checked but .NET doenst let me create an array of checkboxes.
 
You can use a For Each loop to go through all the checkboxes.

Visual Basic:
Dim tmp As Checkbox

For each tmp in GroupBox1.Controls
  If tmp.Checked Then
    'code
  End If
Next
 
Thanks. Is there a way to do this whitout using a GroupBox?
If I do it in a form, with other controls in it, I get a cast exception.
 
Ok, then try something like this:
Visual Basic:
Dim tmp As Controls

For Each tmp in Me.Controls
  If TypeOf tmp is CheckBox Then
    If DirectCast(tmp, CheckBox).Checked Then
      'code
    End If
  End If
Next
 
Back
Top