Hi, I just tried to write a control search function tbut I'm not having much success.

I need it to be able to iterate through all the controls on a forum and all the container controls (group boxes, panels, etc) within and return a reference to the control I'm searching for

this is what I have so far. The problem is that Groupbox and Panel are not considered a ContainerControl so it just skips past that condition.




Public Function FindControl(ByRef Controls As System.Windows.Forms.Control.ControlCollection, ByVal strControlName As String) As Forms.Control
Dim objTemp As Forms.Control
Dim objReturnControl As Forms.Control

For Each objTemp In Controls
If TypeOf (objTemp) Is ContainerControl Then
objReturnControl = FindControl(objTemp.Controls, strControlName)

If Not objReturnControl Is Nothing Then
Return objReturnControl
End If

ElseIf objTemp.Name = strControlName Then
Return objTemp
End If
Next

Return Nothing

End Function