SelectedIndex

Description

Obtains the number of the selected item in a ListBox or ListView control.

Applies to

ListBox and ListView controls

Syntax

listcontrolname.SelectedIndex ( )

Argument

Description

listcontrolname

The name of the ListBox or ListView control in which you want to locate the selected item


Return value

Integer.

Returns the index of the selected item in listcontrolname. If more than one item is selected, SelectedIndex returns the index of the first selected item. If there are no selected items or an error occurs, SelectedIndex returns -1. If listcontrolname is null, SelectedIndex returns null.

Usage

SelectedIndex and SelectedItem are meant for lists that allow a single selection only (when the MultiSelect property for the control is false).

When the MultiSelect property is true, SelectedIndex gets the index of the first selected item only. Use the State function, instead of SelectedIndex, to check each item in the list and find out if it is selected. Use the Text function to get the text of any item in the list.

Examples

If item 5 in lb_actions is selected, then this example sets li_Index to 5:

integer li_Index
li_Index = lb_actions.SelectedIndex()

These statements open the window w_emp if item 5 in lb_actions is selected:

integer li_X
li_X = lb_actions.SelectedIndex()
If li_X = 5 then Open(w_emp)

See also

SelectedItem