Introduction
Have you ever tried to get a reference to a winform control that you have added to a container? I was bl...y annoyed to find out that Microsoft hadn't included that obvious functionality in VB.NET, so I wrote a function to do it. It requires the control container and the name of the control you are looking for.
Code
Function getControlFromName(ByRef containerObj As Object, _
ByVal name As String) As Control
Try
Dim tempCtrl As Control
For Each tempCtrl In containerObj.Controls
If tempCtrl.Name.ToUpper.Trim = name.ToUpper.Trim Then
Return tempCtrl
End If
Next tempCtrl
Catch ex As Exception
End Try
End Function
Use
To use it, enclose it in a CType function to give you a useful reference to the control. Like this..
Dim tempCtrl As Button = _
CType(getControlFromName(TabControl1.TabPages(tabIndex), "btnName"), Button)
That's it! Hope you find it useful. :D
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.