Home All Groups Group Topic Archive Search About

Finding embedded controls?

Author
26 Sep 2006 3:56 PM
IdleBrain
Hello,
I am trying to write code to clear all the textboxes on a VB.NET
windows form using:

            Dim ctrl As Control
            For Each ctrl In Me.Controls
                'Add your code here
                If TypeOf ctrl Is TextBox Then
                    ctr.text = ""
                End If
            Next

When I debug, I realized that none of the text boxes are being
recognized as they are present within tabcontrol and embedded within a
frame.

So how exactly do we find out all the controls that are present on a
tabpage and are embedded within a frame?

Any Help is appreciated.

Author
26 Sep 2006 4:58 PM
IdleBrain
I found out the solution...
Dim ctrl, ctrl2 As Control
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is Panel Then
            For Each ctrl2 In ctrl.Controls
                If ctrl2.Text = "Go" Then
       ' Do Something
          End If
            Next
End If
Author
26 Sep 2006 10:47 PM
Dennis
That works if you are only looking for the panel's child controls.  What if
you have a  panel within a panel that contains textboxes?  Try recursion.
--
Dennis in Houston


Show quoteHide quote
"IdleBrain" wrote:

> I found out the solution...
> Dim ctrl, ctrl2 As Control
>     For Each ctrl In Me.Controls
>         If TypeOf ctrl Is Panel Then
>             For Each ctrl2 In ctrl.Controls
>                 If ctrl2.Text = "Go" Then
>        ' Do Something
>           End If
>             Next
> End If
>
>