Results 1 to 8 of 8

Thread: Problem with enumerating all the child controls

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    16

    Unhappy 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......
    Last edited by kalagammaii; Oct 18th, 2008 at 12:51 AM.

  2. #2
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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 )

  4. #4
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    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

  5. #5
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    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.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    16

    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.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Boston, MA
    Posts
    391

    Re: Problem with enumerating all the child controls

    sorry I didn't understand. do you mean from all active windows outside of your program?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2008
    Posts
    16

    Re: Problem with enumerating all the child controls

    Ya. All active windows outside my program.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width