If you click this link to see this image, I have a listbox containing various numerical items. I like to know how I can get each item from the list and store it to the textboxes.
Since each textbox is named TextBox1, TextBox2, TextBox3, etc, I tried using this code,
For i = 1 To 15
Me.Controls(String.Format("TextBox{0}", i)).Text = item.Value
Next
But it only gets the final item from the textbox and puts them all in the first 15 Textboxes. Click to view the output.
What I would like is a loop code that will get the first item from the listbox and store it in textbox1, get the second item from the listbox and store it in textbox2, and so on.
Any help is appreciated. Thank you
As per jmc's suggestion you should also pull a different item from the list:
For i = 1 To 15
Me.Controls(String.Format("TextBox{0}", i)).Text = LISTBOXNAME.Items(i - 1).Value
^^^^^^^^^^^^^^^^^^^^^^^^
Next
Remember that arrays are indexed from 0
-- none of this is a great way to do these things, incidentally. Your textboxes should be well named, you should parse your text into proper class objects with named properties etc.. but if all youre after is a quick hack now that will be hard to maintain in the future (as having a single form with X textboxes on named textbox1, 2, ... 37 wwould be) then it'll suffice