Solved

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

Posted on 2011-02-17
5
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 86

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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