Gets or sets the currently selected item in the ListBox.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
For a standard ListBox, you can use this property to determine which item is selected in the ListBox. If the SelectionMode property of the ListBox is set to either SelectionMode.MultiSimple or SelectionMode.MultiExtended (which indicates a multiple-selection ListBox) and multiple items are selected in the list, this property can return any selected item.
To retrieve a collection containing all selected items in a multiple-selection ListBox, use the SelectedItems property. If you want to obtain the index position of the currently selected item in the ListBox, use the SelectedIndex property. In addition, you can use the SelectedIndices property to obtain all the selected indexes in a multiple-selection ListBox.
The following code example demonstrates how to use the SelectedIndexChanged event to search for and select an item in a different ListBox control. The example uses the SelectedIndexChanged event to determine when the selected item in the ListBox is changed. The example code then reads the text of the item using the property and calls the FindString method on a different ListBox using the text returned by in the first ListBox. If an item is found in the other ListBox, the item is selected. This example requires that two ListBox controls, named listBox1 and listBox2, have been added to a form and that both ListBox controls contain items that are identical. The example also requires that the event-handling method defined in the example is connected to the SelectedIndexChanged event of listBox1.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.