How do I get the SelectedItem or SelectedIndex of ListView in vb.net?
VB6:
Listview1.selecteditem
VB10:
Listview1.FocusedItem.Text
Here's the answer that I found for my question:
urlList1.FocusedItem.Index
And I am getting selected item value by:
urlList1.Items(urlList1.FocusedItem.Index).SubItems(0).Text
ListView
returns collections of selected items and indices through the SelectedItems
and SelectedIndices
properties. Note that these collections are empty, if no item is currently selected (lst.SelectedItems.Count = 0
). The first item that is selected is lst.SelectedItems(0)
. The index of this item in the Items
collection is lst.SelectedIndices(0)
. So basically
lst.SelectedItems(0)
is the same as
lst.Items(lst.SelectedIndices(0))
You can also use check boxes. Set CheckBoxes
to True
for this. Through the CheckedItems
and CheckedIndices
properties you can see which items are checked.