How do i get the SelectedItem or SelectedIndex of ListView in vb.net

前端 未结 7 1935
闹比i
闹比i 2020-12-10 13:04

As you know by question that what I want. I was using listbox. In ListBox we can get selected item by a simple line of code: listbox1.SelectedItem.

7条回答
  •  庸人自扰
    2020-12-10 13:54

    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.

提交回复
热议问题