Syntax 1 When you know the text of an item
Description
Finds and highlights an item in a ListBox when you can specify
some or all of the text of the item.
Controls
ListBox, DropDownListBox, PictureListBox, and DropDownPictureListBox controls
Syntax
1 |
<span>listboxname</span>.<span>SelectItem</span> ( <span>item</span>, <span>index</span> ) |
Argument |
Description |
---|---|
listboxname |
The name of the ListBox control in which |
item |
A string whose value is the starting |
index |
The number of the item after which you |
Return Values
Integer. Returns the index number of
the selected item. If no match is found, SelectItem returns
0; it returns -1 if an error occurs. If any argument’s
value is null, SelectItem returns null.
Usage
SelectItem begins searching for the desired
item after the item identified by index. To
match, the item must start with the specified text; however, the
text in the item can be longer than the specified text.
To find an item but not select it, use the FindItem function.

SelectItem has no effect on a ListBox or
PictureListBox whose MultiSelect property is true.
Instead, use SetState to select items without
affecting the selected state of other items in the list.

To clear the edit box of a DropDownListBox or DropDownPictureListBox
that the user cannot edit, use Syntax 2 of SelectItem.
Examples
If item 5 in lb_Actions is
Delete Files, this example starts searching after item 2, finds
and highlights Delete Files, and sets li_Index to
5:
1 |
integer li_Index |
1 |
li_Index = lb_Actions.<span>SelectItem</span>("Delete Files", 2) |
If item 4 in lb_Actions is
Select Objects, this example starts searching after item 2, finds
and highlights Select Objects, and sets li_Index to
4:
1 |
integer li_Index |
1 |
li_Index = lb_Actions.<span>SelectItem</span>("Sel", 2) |