Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controls collection question - beginner's query

Status
Not open for further replies.

mogura

Programmer
Sep 6, 2003
22
GB
I've got a group box with 10 check boxes on a form and a 'Select All' button and Reset button. In the General Declarations I've declared Dim c as Control, then in the click event of the 'Select All' button I've got the following code:

For Each c in Controls
If Typeof (c) Is Checkbox
c.Checked = True
End If
Next

I'm having build problems, however, and the message "Checked is not a member of 'Systems.Windows.Forms.Control'"

Is there something blindingly obvious I'm overlooking?

Any help would be great.
 
Code:
For Each c in Controls
   If Typeof (c) Is Checkbox
      Dim ch As CheckBox = c
      ch.Checked = True   
   End If
Next
 
Thanks. This works, the above message no longer appears and all the checkboxes are selected when I click 'Select All'if I haven't got them placed in a groupbox, but if they're placed in a groupbox, they aren't selected - nothing happens.

Any suggestions would be much appreciated.
 
The CheckBoxes in the GroupBox are in the GroupBoxe's Controls collection, not the form's Controls collection. There are plenty of examples in this forum. Do a search for recursion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top