Solved

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

Posted on 2011-02-17
5
253 Views
Last Modified: 2012-05-11
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
Comment
Question by:BemboX
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34919691
foreach (Control c in parent.Controls)
            {
                string foo = c.GetType().ToString();
                
                if (c.HasControls())
               {

               }
            }

Open in new window

0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34919695
Ooops remove the string foo line. I forgot to cut it out.
0
 

Author Comment

by:BemboX
ID: 34919812
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 34919975
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
 

Author Comment

by:BemboX
ID: 34920011
Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now