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
Nov 25, 2002

FindControlRecursive - Find a control in a hierarchy of controls

' Find a control in a hierarchy of controls
' Example:
'   Dim txtCtl As Control = FindControlRecursive(DataGrid1, "FirstNameTextBox")

Function FindControlRecursive(ByVal ctrl As Control, _
    ByVal id As String) As Control
    ' Exit if this is the control we're looking for.
    If ctrl.ID = id Then Return ctrl

    ' Else, look in the hiearchy.
    Dim childCtrl As Control

    For Each childCtrl In ctrl.Controls
        Dim resCtrl As Control = FindControlRecursive(childCtrl, id)
        ' Exit if we've found the result
        If Not resCtrl Is Nothing Then Return resCtrl
    Next
End Function


' Note: This code is taken from Francesco Balena's
' "Programming Microsoft Visual Basic .NET" - MS Press 2002, ISBN 0735613753
' You can read a free chapter of the book at 
' http://www.vb2themax.com/HtmlDoc.asp?Table=Books&ID=101000
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


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

 

 

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