ListBox Control

Description

A ListBox control displays a list of items from which the operator can select one or more.

Usage

Use the ListBox control to display a static list of items from which the operator can choose.

To add items to a list box
Use the AddItem property at runtime to add items to a listbox. This is normally done in the form load event.

  GSet frmSetup.lstModels.AddItem, "Model1"  
  GSet frmSetup.lstModels.AddItem, "Model2"  
  GSet frmSetup.lstModels.AddItem, "Model3"  

Optionally, you can have the list sorted by set the Sorted property to True.

To determine which item was selected
Use the SelectedIndex property to determine the user selection. If no item has been selected, then SelectedIndex is -1.

  Integer index  
  GGet frmSetup.lstModels.SelectedIndex, index  

The List array
You can access all of the items in a list using the List array property.

  Integer i, count  
  String item$  
  GGet frmSetup.lstModels.ListCount, count  
  For i = 0 To count- 1  
    GGet frmSetup.lstModels.List(i), item$  
  Next i  

You can delete an item by setting the List property to an empty string.

  GSet frmSetup.lstModels.List(0), ""  
  Setting ListBox Appearance  
  Use the BorderStyle, ForeColor, BackColor, Font,  
  properties to change the appearance of the listbox.  

Setting ListBox Appearance
Use the BorderStyle, ForeColor, BackColor, Font, properties to change the appearance of the listbox.

ListBox Control Properties

Property Description
AddItem Adds an item to the list at runtime. (Only available from SPEL+ programs)
BackColor

The background color for the control.

Default: Window

BorderStyle

The border used for the control.

Default: Fixed3D

Enabled

Sets whether the control is enabled at runtime.

Default: True

EventTaskType

The type of task used for events.

Default: Normal

Font

The font for the control text.

Default: Microsoft Sans Serif 8.25 pt

FontBold

The bold attribute for the current font

Default: False

FontItalic

The italic attribute for the current font

Default: False

FontName

The name for the current font

Default: Microsoft Sans Serif

FontSize

The size for the current font in points

Default: 8.25

ForeColor

The foreground color for the control text.

Default: WindowText

Height The height of the control in pixels.
Left The left coordinate of the control in pixels.
List Use to access the items in the list at runtime. (Only available from SPEL+ programs)
ListCount Use to get the number of items in the list at runtime.
Name

The name of the control.

Default: ListBoxXX

SelectedIndex Use to determine which item has been selected by the operator at runtime. (Only available from SPEL+ programs)
Sorted

Sets whether to sort the items in the list or not.

Default: False

TabIndex The tab index of the control.
ToolTipText

The text used in the control’s tooltip.

Default: Empty

Top The top coordinate of the control in pixels.
Visible

Whether the control is visible or not at runtime.

Default: True

Width The width of the control in pixels.

ListBox Control Events

Event Description
Click Executes when the user clicks the control with the mouse.
DblClick Executes when the user double clicks the control with the mouse.