Hi folks,
I need to locate a control within a WinForm that may be located a few
layers deep into the container hierarchy. The answer seems to be
recursion, since there is no FindControl method on the standard Windows
Form class.
Problem I'm having is that this code can't retrieve a control past the
second layer. If the control is buried at level three, this code can
find it but the return value is Nothing.
Would really appreciate any help.
Thanks.
Function FindControl(ByVal Parent As System.Windows.Forms.Control,
ByVal strCtlName As String) As System.Windows.Forms.Control
Dim tmp As System.Windows.Forms.Control
Dim blnFound As Boolean
Try
For Each tmp In Parent.Controls
blnFound = (tmp.Name = strCtlName)
If blnFound Then
Exit For
Else
tmp = FindControl(tmp, strCtlName)
End If
Next
Return tmp
Catch ex As System.Exception
DisplayExceptionInfo(ex)
End Try
End Function
Form1
TabControl
TabPage
Grid1 -- FindControl gets to this, but can't pass it back
------------------------
Dan Souk
Finna Technologies, Inc.
2410 Lindsay Ct
West Chicago, IL 60185
+1-630-762-8257 phone
+1-630-762-8258 fax
http://www.finnatech.com
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.