Using ListBox controls

You can present information to the user in simple lists with scrollbars. Depending on how you design your application, the user can select one or more list items to perform an action, based on the list selection.

You add ListBox controls to windows in the same way you add other controls: select ListBox from the Insert>Control menu and click the window.

Adding items to list controls

In the painter To add new items, use the control’s Items property page.

StepsTo add items to a ListBox:

  1. Select the Items tab in the Properties view for the control.

  2. Enter the names of the items for the ListBox.

In a script Use the AddItem and InsertItem functions to dynamically add items to a ListBox at runtime. AddItem adds items to the end of the list. However, if the list is sorted, the item will then be moved to its position in the sort order. Use InsertItem if you want to specify where in the list the item will be inserted.

Table 6-1: Using the InsertItem and AddItem functions

Function

You supply

InsertItem

Item name

Position in which the item will be inserted

AddItem

Item name

For example, this script adds items to a ListBox:

This.AddItem ("Vaporware")
This.InsertItem ("Software",2)
This.InsertItem ("Hardware",2)
This.InsertItem ("Paperware",2)

NoteUsing the Sort property You can set the control’s sort property to true or check the Sorted check box on the General property page to ensure that the items in the list are always arranged in ascending alphabetical order.