How to loop thru each controls ?

  • Thread starter Thread starter Kay
  • Start date Start date
K

Kay

Hi all,

I have a 42 groupboxes in a panel, each groupbox has 3 check boxes in it.

The 42 groupboxes are actually in a panel, and the panel is on the second
tab page of a tab control...

What I need to do is to find out the value of each checkbox (i.e. checked or
not), can anyone tell me how to do it?

I think it would be easier if I can create an array of groupbox like in vb6,
but it seems it's not avaliable in .net ....

Thanks~

Kay
 
Kay said:
I have a 42 groupboxes in a panel, each groupbox has 3 check boxes in it.

The 42 groupboxes are actually in a panel, and the panel is on the second
tab page of a tab control...

What I need to do is to find out the value of each checkbox (i.e. checked
or not), can anyone tell me how to do it?

You will have to recursively enumerate the controls. Check out the
implementation of 'FindControl' here:

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>
 
You don't say how you identify each checkbox, but try this (not tested, but
I think it works):

Dim al As New List(Of CheckBox)

Foreach gb as GroupBox in panel.Controls
Foreach rb as CheckBox in gb.Controls
If rb.Checked Then
al.Add(rb)
End If
Next
Next

Chuck Gantz
 
Back
Top