Home All Groups Group Topic Archive Search About

How to loop thru each controls ?

Author
5 Jan 2006 6:42 AM
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

Author
5 Jan 2006 12:23 PM
Herfried K. Wagner [MVP]
"Kay" <k*@micxsoft.com> schrieb:
> 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>

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
6 Jan 2006 6:40 AM
Chuck Gantz
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


Show quoteHide quote
"Kay" <k*@micxsoft.com> wrote in message
news:e7fxoMcEGHA.1424@TK2MSFTNGP12.phx.gbl...
> 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
>