ListBox.SelectedIndices Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets a collection that contains the zero-based indexes of all currently selected items in the ListBox.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member SelectedIndices : ListBox.SelectedIndexCollection with get

Property Value

Type: System.Windows.Forms.ListBox.SelectedIndexCollection

A ListBox.SelectedIndexCollection containing the indexes of the currently selected items in the control. If no items are currently selected, an empty ListBox.SelectedIndexCollection is returned.

For a multiple-selection ListBox, this property returns a collection containing the indexes to all items that are selected in the ListBox. For a single-selection ListBox, this property returns a collection containing a single element containing the index of the only selected item in the ListBox. For more information about how to manipulate the items of the collection, see ListBox.SelectedIndexCollection.

The ListBox class provides a number of ways to reference selected items. Instead of using the SelectedIndices property to obtain the index position of the currently selected item in a single-selection ListBox, you can use the SelectedIndex property. If you want to obtain the item that is currently selected in the ListBox, instead of the index position of the item, use the SelectedItem property. In addition, you can use the SelectedItems property if you want to obtain all the selected items in a multiple-selection ListBox.

The following code example demonstrates how to use the FindString method to search for all instances of the search text in the items of the ListBox. The example uses the version of the FindString method that enables you to specify a starting search index from which to do a continual search of all items in the ListBox. The example also demonstrates how to determine when the FindString method begins searching from the top of the list after it reaches the bottom of the list of items to prevent a recursive search. Once items are found in the ListBox, they are selected using the SetSelected method.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top