|
-
Jan 7th, 2006, 02:28 AM
#1
Thread Starter
Junior Member
[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
-
Jan 7th, 2006, 02:48 AM
#2
Thread Starter
Junior Member
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
-
Jan 7th, 2006, 02:53 AM
#3
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|