Yliah Yliah - 1 year ago 88
Vb.net Question

Looping of each 2 TextBoxes

I've been thinking of on how to loop my textboxes that has an integer as a value and insert it in a listview. My textboxes starts at Textbox2.Text and ended in Textbox41.Text. The thing is I need to check each 2 textboxes (ex. textbox2 and textbox3)and insert in a listview. I dont know how to loop the other textboxes.

If TextBox2.Text <> Nothing And TextBox3.Text <> Nothing Then
Pid += 1
At = TextBox2.Text
Bt = TextBox3.Text

Table = ListView1.Items.Add(Pid)
With Table
End With

TextBox2.Text = Nothing
TextBox3.Text = Nothing
End If
Catch ex As Exception
MsgBox("Must be numbers!")
End Try

Answer Source

If your application is Windows Form, this is how you can get all integer values...

Dim intList As New List(Of Integer)()
For Each c As Control In Me.Controls
    If c.GetType Is GetType(TextBox) Then
        Dim txtControl As TextBox = CType(c, TextBox)
        If Integer.TryParse(txtControl.Text, 0) Then
        End If
    End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download