Saturday, February 2, 2013

HOW TO GET THE SELECTED ITEM(S) IN A LIST VIEW CONTROL


HOW TO GET THE SELECTED ITEM(S) IN A LIST VIEW CONTROL

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.

No comments:

Post a Comment