State PowerScript function
Description
Determines whether an item in a ListBox control is highlighted.
Controls
ListBox and PictureListBox controls
Syntax
1 |
<span>listboxname</span>.<span>State</span> ( <span>index</span> ) |
Argument |
Description |
---|---|
listboxname |
The name of the ListBox or PictureListBox |
index |
The number of the item for which you |
Return Values
Integer. Returns 1 if the item in listboxname identified
by index is highlighted and 0 if it is not.
If the index does not point to a valid item number, State returns -1.
If any argument’s value is null, State returns null.
Usage
The State and SetState functions
are meant for a ListBox that allows multiple selections (its MultiSelect
property is true). To find all of a list’s
selected items, loop through the list, checking the state of each
item.
The SelectedItem and SelectItem functions
are meant for single-selection ListBox controls. SelectedItem reports
the selection directly with no need for looping. In a multiple-selection
ListBox control, SelectedItem reports the first selected
item only.
When you know the index of an item, you can use the Text function
to get the item’s text.
Examples
If item 3 in lb_Contact is
selected (highlighted), then this example sets li_Item to
1:
1 |
integer li_Item |
1 |
li_Item = lb_Contact.<span>State</span>(3) |
The following statements obtain the text of all the
selected items in a ListBox that allows the user to select more
than one item. The MessageBox function displays
each item as it is found. You could include other processing that created
an array or list of the selected values:
1 |
integer li_ItemTotal, li_ItemCount |
1 |
1 |
// Get the number of items in the ListBox. |
1 |
li_ItemTotal = lb_contact.TotalItems( ) |
1 |
1 |
// Loop through all the items. |
1 |
FOR li_ItemCount = 1 to li_ItemTotal |
1 |
// Is the item selected? If so, display the text |
1 |
IF lb_Contact.<span>State</span>(li_ItemCount) = 1 THEN & |
1 |
MessageBox("Selected Item", & |
1 |
lb_Contact.text(li_ItemCount)) |
1 |
NEXT |
This statement executes some statements if item 3
in the ListBox lb_Contact is highlighted:
1 |
IF lb_Contact.<span>State</span>(3) = 1 THEN ... |