Splitting the contents of a list view into multiple textboxes?

vbdotnetnoob

New member
Joined
May 16, 2010
Messages
3
Programming Experience
Beginner
Hello, I am obviously quite new here, I have searched this forum as well as many other resources and cant figure out for the life of me how to do this.

Essentially what i am trying to do is used stored data in a listview to populate multiple textboxes...almost like you would a database i suppose or something similar.

Can someone please save me from this black hole piece of code? Thank you!!!
 
Each row in the ListView corresponds to a ListViewItem. You can get them by index from the Items collection, so you can also use a For or For Each loop to visit them all. Each item has a SubItems collection, which you can also index or loop through to get each ListViewSubItem in that row. Each of those subitems has a Text property, which contains the text displayed in that field.

So, get the item you want, then get each subitem from that item and transfer its Text to the appropriate TextBox.
 
thank you for that response...I understand that part...However I am unable to get the code right that actually functions properly...Do you have a quick example by chance? As stated I am really new to .net i am a php developer merging over so any extra help would be incredible.
 
Quick example:
VB.NET:
Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
    
TextBox1.Text = ListView1.SelectedItems.Item(0).Text 
TextBox2.Text = ListView1.SelectedItems.Item(0).SubItems(1).Text 
TextBox3.Text = ListView1.SelectedItems.Item(0).SubItems(2).Text 
TextBox4.Text = ListView1.SelectedItems.Item(0).SubItems(3).Text 
'etc
End Sub
 
Back
Top