How to get the Name Of Multiple TextBoxes Using For Each Loop
Submitted by janobe on Saturday, May 17, 2014 - 09:45.
In this tutorial I will teach you how to get the name of a specific TextBoxes by using For Each Loop in VB.Net. This method will determine what are the names of your TextBoxes that you drag it on the Form. You will be able to find out the specific name of the TextBox because it will be seen in each TextBoxes.
So let’s begin:
Open Visual Studio and create a new Project. Drag all the TextBoxes and a Button. Then, do the Form just like this.
Double click the Button to fire the
After that, Loop the control that you have created.
Then, check if the type of the control is a Textbox and if it’s true, then perform the process that puts the name of the TextBox to itself. Do this code inside the Loop.
And here are the codes that we made.
Press F5 to run your project and click the Button to fire the code in the method.

click
event handler in the Method.
Now, create a variable that represents the control.
- Dim txt As Control
- For Each txt In Me.Controls
- Next
- If txt.GetType Is GetType(TextBox) Then
- txt.Text = txt.Name
- End If
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim txt As Control
- For Each txt In Me.Controls
- If txt.GetType Is GetType(TextBox) Then
- txt.Text = txt.Name
- End If
- Next
- End Sub
Add new comment
- 267 views