I have a listview and I want to set it up so when you click on an item that item's subitem get put into a variable. How do i do this in VB.NET?
Printable View
I have a listview and I want to set it up so when you click on an item that item's subitem get put into a variable. How do i do this in VB.NET?
First set the listview's property MultiSelect to false (to make sure the user is only able to select one item at a time), then add code to the lvwItems.Click event:
SelectedItems(0) will be the first (only) selected item in the ListView.SelectedItems collection. Subitems begin counting at 1, not zero.Code:Private Sub lvwItems_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwItems.Click
Dim strFoo As String = lvwItems.SelectedItems(0).SubItems(1).Text
MsgBox(strFoo)
End Sub
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformslistviewitemlistviewsubitemclasstopic.htm