I want to get indices of all the items that are selected in given listbox, there is a SelectedItems
method which return a collection of items:
listbox.SelectedItems
But there is no SelectedIndices
method. The collection also doesn't contain an index for each item.
How can I know which item was selected in my listbox?
If you're binding a
List
or anObservableCollection
of items to theListBox
useYou can simply use
IndexOf
to find their index in the collection of items. For example, when binding a collection of items:You can find the selected index as follows: