My script has 20 text boxes for a maximum of 10 Listview Items. There is only one sub-item for each item. My goal is to have these text boxes auto fill for each item added to the ListView.
Example of the textboxes:
Currently, the script bellow has two for-loop statements. The first one will click through all the items in the listview. The second for will input the values to the text boxes. I'm unsure how to incorporate a way to have the script fill all the text boxes. I imagine a case statement will be used.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For I As Integer = 0 To ListView1.Items.Count - 1
ListView1.Items(I).Selected = True
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox1.Text = item.Text
OpenModule.TextBox2.Text = item.SubItems(1).Text
Next
Next
End Sub
Any help or ideas is appreciated.
This is a working response to my question that I managed to create. Please keep in mind that the order of populating the textboxes is not relevant to my issue. I'm sure this code can be shortened somehow and if done I'll mark that response as solved; until then, this is a working alternative.
Dim count = ListView1.Items.Count - 1 ' Using ListView1.Items.Count to get max number of rows to prevent error
' Highlight each item
For index As Integer = 0 To count
ListView1.Items(index).Selected = True
' First Selected Item
If index = 0 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox1.Text = item.Text
OpenModule.TextBox2.Text = item.SubItems(1).Text
Next
End If
' Second Selected Item
If index = 1 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox3.Text = item.Text
OpenModule.TextBox4.Text = item.SubItems(1).Text
Next
End If
' Third Selected Item
If index = 2 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox5.Text = item.Text
OpenModule.TextBox6.Text = item.SubItems(1).Text
Next
End If
' Forth Selected Item
If index = 3 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox7.Text = item.Text
OpenModule.TextBox8.Text = item.SubItems(1).Text
Next
End If
' Fith Selected Item
If index = 4 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox9.Text = item.Text
OpenModule.TextBox10.Text = item.SubItems(1).Text
Next
End If
' Sixth Selected Item
If index = 5 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox11.Text = item.Text
OpenModule.TextBox12.Text = item.SubItems(1).Text
Next
End If
' Seventh Selected Item
If index = 6 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox13.Text = item.Text
OpenModule.TextBox14.Text = item.SubItems(1).Text
Next
End If
' Eighth Selected Item
If index = 7 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox15.Text = item.Text
OpenModule.TextBox16.Text = item.SubItems(1).Text
Next
End If
' Ninth Selected Item
If index = 8 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox17.Text = item.Text
OpenModule.TextBox18.Text = item.SubItems(1).Text
Next
End If
' Tenth Selected Item
If index = 9 Then
For Each item As ListViewItem In ListView1.SelectedItems
OpenModule.TextBox19.Text = item.Text
OpenModule.TextBox20.Text = item.SubItems(1).Text
Next
End If
' Deselect Current Item
ListView1.Items(index).Selected = False
Next