I have a listbox(detailed view).My question is how do I get the index of the selected item?
Eventually,how to get the text at the index,but that should be easy.
I have a listbox(detailed view).My question is how do I get the index of the selected item?
Eventually,how to get the text at the index,but that should be easy.
The selected index is in the SelectedIndex
property.
The selected text is in the Text
property.
ListBox.SelectedItem Property:
Gets or sets the currently selected item in the ListBox.
Or, naturally, ListBox.SelectedItems Propery:
Gets a collection containing the currently selected items in the ListBox.
... Remarks
For a multiple-selection ListBox, this property returns a collection containing all items that are selected in the ListBox. For a single-selection ListBox, this property returns a collection containing a single element containing the only selected item in the ListBox. For more information about how to manipulate the items of the collection, see ListBox..::.SelectedObjectCollection.
The ListBox class provides a number of ways to reference selected items. Instead of using the SelectedItems property to obtain the currently selected item in a single-selection ListBox, you can use the SelectedItem property. If you want to obtain the index position of an item that is currently selected in the ListBox, instead of the item itself, use the SelectedIndex property. In addition, you can use the SelectedIndices property if you want to obtain the index positions of all selected items in a multiple-selection ListBox.
I think you mean ListView (not ListBox) so use SelectedItems and SelectedIndices properties.