• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Full list of controls in a form including those that are inside a container

I have a form with textboxes, labels, comboboxes and containers like tabpage or panels. If I use:
for each c in me.controls
....
I obtain each control in the form but not in the containers.
How can I obtain a list of controls in the form, its containers, containers inside containers, etc.?
0
BemboX
Asked:
BemboX
  • 2
  • 2
1 Solution
 
rawinnlnx9Commented:
foreach (Control c in parent.Controls)
            {
                string foo = c.GetType().ToString();
                
                if (c.HasControls())
               {

               }
            }

Open in new window

0
 
rawinnlnx9Commented:
Ooops remove the string foo line. I forgot to cut it out.
0
 
BemboXAuthor Commented:
Thanks for your answer, but I want to obtain a full list of controls inside containers, not a list of containers, then a full list of textboxes, comboboxes, radiobuttons, etc. Sorry if I didnĀ“t express it correctly.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use a recursive routine like this:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RecurseControls(Me)
    End Sub

    Private Sub RecurseControls(ByVal cont As Control)
        For Each ctl As Control In cont.Controls
            Debug.Print(ctl.Name & ": " & ctl.GetType.ToString)
            If ctl.HasChildren Then
                RecurseControls(ctl)
            End If
        Next
    End Sub

End Class

Open in new window

0
 
BemboXAuthor Commented:
Thanks
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now