Reputation: 33
I'm trying to refer to a control by a variable name. The control is located in a panel within a tab control.
I can refer to a control if it's on the parent form like this:
Me.Controls("TextBoxName").Text = "test text"
Is there an easy way of referring to any control regardless of where it is?
Failing that, how do I loop through all the controls to find it? - I'm not sure how to get a control that's on a tab.
Thanks!
Upvotes: 0
Views: 660
Reputation: 180
Here as per @dr.null refered you, You can just find control by putting control name directly
Here is Code for your reference
Dim Controls() As Control
Controls= Me.Controls.Find("TextBox2", True)
If Not IsNothing(Controls) Then
For Each cntrl As Control In Controls
cntrl.Text = "text here "
Next
End If
Here you do not need to check panel name as windows form does not allow to enter duplicate control name
Upvotes: 1