Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: beginner
Jul 14, 2003

GetAllControls - Retrieving all the controls inside a container and its sub-containers

' Returns an array with all the controls in the specified container control and 
' its child containers
' Example:
'    ' print the name of all the controls on the form and its child container 
' controls
'    Dim ctl As Control
'    For Each ctl In GetAllControls(Me)
'        Debug.WriteLine(ctl.Name)
'    Next

Function GetAllControls(ByVal container As Control) As Control()
    Dim al As New ArrayList
    Dim ctl As Control
    For Each ctl In container.Controls
        GetAllControlsHelper(ctl, al)
    Next
    Return al.ToArray(GetType(Control))
End Function

Sub GetAllControlsHelper(ByVal container As Control, ByVal al As ArrayList)
    ' add this control to the ArrayList
    al.Add(container)
    ' add all its child controls, by calling this routine recursively
    Dim ctl As Control
    For Each ctl In container.Controls
        GetAllControlsHelper(ctl, al)
    Next
End Sub
Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap