[RESOLVED] Hard to find a control
I'm trying to find the values in textboxes, checkboxes and radiobuttons in a windows form so I'm trying to use this function
VB Code:
For Each control In Me.Controls
RichTextBox1.Text = RichTextBox1.Text & Chr(13) & control.Name
Next
But I have the following controls inside other controls and I can't find seem to be able to find them. For instance, the textbox (txtPtName) is inside a table layout panel (TableLayoutPanel1) and the TableLayoutPanel1 is inside a panel (Panel1)
Panel1
--- TableLayoutPanel1
-------- txtPtName
My question is: How can I search for every checkbox, radiobutton or a textbox without searching for them inside other controls? I really need this please.. thanks
Re: Hard to find a control
solved.. used this function
Private Sub CheckControls(ByVal ctl As Control, controlnamestring As String)
If ctl.Name = controlnameString then
'do something
Exit Sub
End If
If ctl.HasChildren Then
For Each c As Control In ctl.Controls
CheckControls(c, controlnamestring)
Next
End If
End Sub
Private Sub FindControl()
CheckControls(Me, "TextBox1")
End Sub
Re: [RESOLVED] Hard to find a control
You don't need a recursive method. The GetNextControl method will follow the tab order, including nested controls:
VB Code:
Private Function GetControlByName(ByVal name As String) As Control
Dim ctl As Control = Me.GetNextControl(Me, True)
While Not ctl Is Nothing
If ctl.Name = name Then
Return ctl
End If
ctl = Me.GetNextControl(ctl, True)
End While
Return Nothing
End Function