devxlogo

FindControlRecursive – Find a control in a hierarchy of controls

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    NextEnd 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

See also  5 Strategies for Supercharging Your CRM
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist