Solved

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

Posted on 2011-02-17
5
252 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
Comment Utility
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
Comment Utility
Ooops remove the string foo line. I forgot to cut it out.
0
 

Author Comment

by:BemboX
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

6 Experts available now in Live!

Get 1:1 Help Now