-----Original Message-----
Hi Rich,
It doesn't appear that the form offers an easy way to find a control given
it's name. It's easy to do this by looping through the Controls collection
and find the one whose Name property matches the search string.
Note: You have to watch for container controls (e.g. Panel, GroupBox,
TabControl, etc.).If the control you're looking for is on a container
control the code below won't find it because it will belong to the container
control's Controls collection.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim ctl As Control
For i As Integer = 1 To 5
ctl = Me.FindControl("textbox" & i)
If Not ctl Is Nothing Then
ListBox1.Items.Add(ctl.Name)
End If
Next
End Sub
Private Function FindControl(ByVal name As String) As Control
For Each ctl As Control In Me.Controls
If ctl.Name.ToUpper = name.ToUpper Then
Return ctl
End If
Next
Return Nothing
End Function
--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
Hello,
I have a form with 5 textboxes named txt0, txt1, txt2,
txt3, tx4.
In VB6 I could iterate through these with
For i = 0 to 4
debug.print Me.controls("txt" & i).Name
Next
In dotNet, I can't seem to do that.
Console.WriteLine(Me.Controls("txt" & i).Name)
Could someone share how to do this in dotnet vb?
Thanks,
Rich
.