ListBox or ComboBox: AddItem adds an item. RemoveItem removes an item NewIndex returns the index of the item most recently added.
object.AddItem item$ [, itemdata%]
object.InsertItem index%, item$ [, itemdata]
object.RemoveItem index%
object.Clear
object.NewIndex
object:ListBox, ComboBox
item$:sexp
itemdata:iexp
AddItem adds an item to the ListBox or ComboBox. It takes the text for the item and optional the itemdata, a long integer value linked to the item. InsertItem inserts an item at the specified position. Both AddItem and InsertItem return the actual position of the list item.
NewIndex returns the index of most recently added. You can use the NewIndex property with sorted lists when you need a list of values that correspond to each item in the ItemData property array. As you add an item in a sorted list, GFA-BASIC 32 inserts the item in the list in alphabetic order. This property tells you where the item was inserted so that you can insert a corresponding value in the ItemData property at the same index.
RemoveItem removes a specified item from the list. Clear removes all items from the ListBox or ComboBox.
Example 1
Dim i As Int
OpenW 1, 20, 20 , 300, 300
Ocx ListBox lb1 = , 10, 10, 100, 100
For i = 1 To 100 ' Count from 1 to 100.
lb1.AddItem Dec(i, 3) & "Entry "
Next
MsgBox "Choose OK to remove every other entry."
For i = 1 To 50
lb1.RemoveItem i
Next
MsgBox "Choose OK to remove all items from the list box."
lb1.Clear ' Clear list box.
Do
Sleep
Until Me Is Nothing
Example 2
Ocx ComboBox cbx = "", 10, 10, 200, 15 : cbx.Sorted = False
Local n%
For n% = 1 To 100 : cbx.AddItem "Item " & Trim(n%) : Next n%
cbx.InsertItem 50, "Item New"
Do : Sleep : Until Me Is Nothing
Note: index starts from 0, not 1, so to add to position 51, index would be 50.
If you supply a valid value for index, item is placed at that position within the object. If index is omitted, item is added at the proper sorted position (if the Sorted property is set to True) or to the end of the list (if Sorted is set to False).
{Created by Sjouke Hamstra; Last updated: 15/09/2021 by James Gaite}