Reputation: 231
I am creating an application for windows desktop using Visual Basic 2010 Express. The program I am designing has three main controls: a ListView, a TextBox, and a Button. What I need is when the user clicks a row inside of the ListView control, the TextBox will show the text within the first SubItem. To elaborate, the ListView control has two columns (Name and Description). In the SelectedIndexChanged event, I need code that will display the Description text in the TextBox (the ListView SubItem).
I would post my code to show what I have done, but I do not know where to even start, for all my code has just given me errors. I tried something like this:
textbox1.text = listview1.items.subitems.tostring
But obviously this method is useless and completely off track. I know this is basic, but I do not understand it. Thanks
Upvotes: 1
Views: 35500
Reputation: 457
If you want to get the subitem you clicked on from a listview control simply use ListViewHitTestInfo in a mouse click event i.e
Dim info As ListViewHitTestInfo = lstvw1.HitTest(e.X, e.Y)
MsgBox(info.SubItem.Text)
Upvotes: 2
Reputation: 38915
for the text of the selected LV Item:
textbox1.text = listview1.SelectedItem.ToString
For the text of SubItem N of the First selected Item:
textbox1.text = listview1.SelectedItems(0).SubItems(N).Text
you can also get it using listview1.Items(X).SubItems(N).Text
where X is the index of the Item (row) you want
Upvotes: 6