Syntax 1: For ListBox and DropDownListBox controls
Description
Inserts an item into the list of values in a list box.
Applies to
ListBox and DropDownListBox controls
Syntax
1 |
listboxname.InsertItem ( item, index ) |
Argument |
Description |
---|---|
listboxname |
The name of the ListBox or DropDownListBox into |
item |
A string whose value is the text of the item you |
index |
The number of the item in the list before which you |
Return value
Integer. Returns the final position of the item. Returns -1 if an
error occurs. If any argument’s value is null, InsertItem returns
null.
Usage
InsertItem inserts the new item before the item identified by
index. If the items in listboxname are sorted (its Sorted property is
true), PowerBuilder resorts the items after the new item is inserted.
The return value reflects the new item’s final position in the
list.
AddItem and InsertItem do not update the Items property array. You
can use FindItem to find items added at runtime.
Examples
This statement inserts the item Run Application before the fifth
item in lb_actions:
1 |
lb_actions.InsertItem("Run Application", 5) |
If the Sorted property is false, the statement above returns 5
(the previous item 5 becomes item 6). If the Sorted property is true,
the list is sorted after the item is inserted and the function returns
the index of the final position of the item.
If the ListBox lb_Cities has the following items in its list and
its Sorted property is set to true, then the following example inserts
Denver at the top, sorts the list, and sets li_pos to 4. If the
ListBox’s Sorted property is false, then the statement inserts Denver at
the top of the list and sets li_pos to 1. The list is:
1 2 3 4 |
Albany Boston Chicago New York |
The example code is:
1 2 3 |
string ls_City = "Denver" integer li_pos li_pos = lb_Cities.InsertItem(ls_City, 1) |
See also