Problem with enumerating all the child controls
Hi all,
Am new to VB.Net.Am able to enumerate all the child controls of any parent window which is currently active... But its again and again calling itself untill that parent window is active.
I wan it to be like, once a new parent window is active, it should find all the child controls and then it should stop untill my next parent window is active.
Is there any way to find the total no. of child controls in the active window?
Is there any way to do it?
Please anyone help me.........
Thanks in advance......
Re: Problem with enumerating all the child controls
You're in the wrong section of the forum.
This is VB6.
Maybe one of the moderators will move it for you.
Re: Problem with enumerating all the child controls
Thread moved from 'VB6 and Earlier' forum to VB.Net (VB2002 and later) forum
(this would have been done much sooner if you had clicked the "report" icon to the left of the post ;) )
Re: Problem with enumerating all the child controls
Quote:
Originally Posted by si_the_geek
Thread moved from 'VB6 and Earlier' forum to VB.Net (VB2002 and later) forum
(this would have been done much sooner if you had clicked the "report" icon to the left of the post ;) )
Didn't know that one, I thought it was for tattling on ppl :)
Re: Problem with enumerating all the child controls
If I understand you I think you wish to determine all the controls on a given form as well as the children of the children all the way down. If so then you could do something like this:
Code:
Private Sub MakeControlList()
Dim controls As List(Of Control)
controls = New List(Of Control)
EnumerateControls(controls, Me)
Me.ListBox1.Items.AddRange(controls.ToArray())
Me.ListBox1.DisplayMember = "Name"
End Sub
Private Sub EnumerateControls(ByVal controls As List(Of Control), ByVal child As Control)
Dim c As Control
For Each c In child.Controls
controls.Add(c)
EnumerateControls(controls, c)
Next
End Sub
The list 'controls' will contain a recursive list of all the controls on the form. You can call that anytime on a form to get the list. You may want to consider a different structure such as a tree if you want to preserve the parent/child relationships.
Re: Problem with enumerating all the child controls
I wan it not only for my form, i wan it for any window which is currently active.
but the below mentioned statements can get the controls number only for the form.
EnumerateControls(controls, Me)
Me.ListBox1.Items.AddRange(controls.ToArray())
Me.ListBox1.DisplayMember = "Name"
Please help me out to get it for all the active windows.
Thanks in advance.
Re: Problem with enumerating all the child controls
sorry I didn't understand. do you mean from all active windows outside of your program?
Re: Problem with enumerating all the child controls
Ya. All active windows outside my program.