This example adds the item Edit File to the ListBox lb_Actions:
integer rownbr
string s
s = "Edit File"
rownbr = lb_Actions.AddItem(s)
If lb_Actions contains Add and Run and the Sorted property is FALSE, the statement above returns 3 (because Edit File becomes the third and last item). If the Sorted property is TRUE, the statement above returns 2 (because Edit File becomes the second item after the list is sorted alphabetically).
Adds a new item to the list of values in a list box.
Controls
ListBox and DropDownListBox controls
Syntax
listboxname.AddItem ( item )
Argument Description
listboxname The name of the ListBox or DropDownListBox in which you want to add an item
item A string whose value is the text of the item you want to add
Return value
Integer. Returns the position of the new item. If the list is sorted, the position returned is the position of the item after the list is sorted. Returns -1 if it fails. If any argument's value is NULL, AddItem returns NULL.
Usage
If the ListBox already contains items, AddItem adds the new item to the end of the list. If the list is sorted (its Sorted property is TRUE), PowerBuilder re-sorts the list after the item is added.
A list can have duplicate items. Items in the list are tracked by their position in the list, not their text.
AddItem and InsertItem do not update the Items property array. You can use FindItem to find items added during execution.
Adding many items to a list with a horizontal scrollbar If a ListBox or the ListBox portion of a DropDownListBox will have a large number of items and you want to display an HScrollBar, call the SetRedraw function to turn Redraw off, add the items, call SetRedraw again to set Redraw on, and then set the HScrollBar property to TRUE. Otherwise, it may take longer than expected to add the items.