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.
Applies to
ListBox, DropDownListBox, PictureListBox, and
DropDownPictureListBox controls
Syntax
|
1 |
listboxname.SelectItem ( item, index ) |
|
Argument |
Description |
|---|---|
|
listboxname |
The name of the ListBox control in which you want to |
|
item |
A string whose value is the starting text of the item |
|
index |
The number of the item after which you want to begin the |
Return value
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.
MultiSelect ListBoxes
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.
Clearing the edit box of a drop-down 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 2 |
integer li_Index li_Index = lb_Actions.SelectItem("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 2 |
integer li_Index li_Index = lb_Actions.SelectItem("Sel", 2) |
See also