If you would like to split listbox item into parts, use
ListBox.SelectedIndexChanged Event (System.Windows.Forms)[
^]
Then, inside that event, paste below code:
Dim curItem As String = ListBox1.SelectedItem.ToString()
Dim parts As String() = curItem.Split(New String(){","}, StringSplitOptions.RemoveEmptyEntries)
For i As Integer = 0 To parts.Count()-1
Dim txt As TextBox = DirectCast(Me.Controls("txtBox" & i+1), System.Windows.Forms.TextBox)
txt.Text = parts(i)
Next
You've got "
Index was outside the bounds of the array
", because your for-next loop starts from one and exceed the number of elements in array. See important note from MSDN:
Quote:
The indexes of an array range from 0 to one less than the total number of elements in the array.
More:
DirectCast Operator (Visual Basic) | Microsoft Docs[
^]
Arrays in Visual Basic | Microsoft Docs[
^]