Selected

Returns or sets the selection status of an item in a ListBox control. This property is an array of Boolean values with the same number of items as the List property. Not available at design time.

Syntax

object.Selected(index) [= boolean]

The parts of the Selected property syntax are described in the following table.

Part Description
object An object expression that evaluates to an object.
index The index number of the item in the control.
boolean A Boolean expression specifying whether the item is selected, as described in Settings.

Settings

The settings for boolean are described in the following table.

Setting Description
True The item is selected.
False (Default). The item is not selected.

Remarks

This property is particularly useful when users can make multiple selections. You can quickly check which items in a list are selected. You can also use this property to select or deselect items in a list from code.

If the MultiSelect property is set to 0, you can use the ListIndex property to get the index of the selected item. However, in a multiple selection, the ListIndex property returns the index of the item contained within the focus rectangle, whether or not the item is actually selected.

If a ListBox control's Style property is set to 1 (check boxes), the Selected property returns True only for those items whose check boxes are selected. The Selected property will not return True for those items which are only highlighted.