Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: VB7
Expertise: Intermediate
Oct 6, 2003



Building the Right Environment to Support AI, Machine Learning and Deep Learning

GetControlsByTag - Find all the controls with the specified Tag value

' Find all the controls with the specified Tag value
' Example:
'    Dim ctrls() As Control = GetControlsByTag("OK", Me)
'    Dim ctrl As Control
'    For Each ctrl In ctrls
'        Debug.WriteLine(ctrl.Name)
'    Next

Function GetControlsByTag(ByVal tagToSearch As String, _
    ByVal parentControl As Control) As Control()
    Dim controlList As New System.Collections.ArrayList

    ' add the parent control to the list, if its Tag matches the input string
    If Not parentControl.Tag Is Nothing Then
        If parentControl.Tag.ToString() = tagToSearch Then
        End If
    End If

    ' recursively call this routine for all the child controls
    If parentControl.Controls.Count > 0 Then
        Dim child As Control
        For Each child In parentControl.Controls
            ' add the results of the recursive GetControlsByTag call to the 
            ' current ArrayList
            controlList.AddRange(GetControlsByTag(tagToSearch, child))
    End If

    ' convert the ArrayList to an array of Controls, and return it
    Return controlList.ToArray(GetType(Control))
End Function
Alberto Falossi
Comment and Contribute






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



Thanks for your registration, follow us on our social networks to keep up-to-date