SelectedItem

Description

Obtains the text of the selected item in a ListBox control.

Applies to

ListBox and PictureListBox controls

Syntax

listboxname.SelectedItem ( )

Argument

Description

listboxname

The name of the ListBox or PictureListBox in which you want the text of the currently selected item


Return value

String.

Returns the text of the selected item in listboxname. Returns the empty string ("") if no items are selected. If listboxname is null, SelectedItem 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, SelectedItem gets the text of the first selected item only. Use the State function, instead of SelectedItem, 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 the text of the selected item in the ListBox lb_shortcuts is F1, then this example sets ls_item to F1:

string ls_Item
ls_Item = lb_Shortcuts.SelectedItem()

See also

SelectedIndex

State