ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Developing an application or website / Controls, windows and pages / Controls: Available types / List Box control
  • Overview
  • Initializing a List Box control
  • Initializing an element
  • Populating a List Box control
  • Selecting an element in a List Box control
  • Selecting a row
  • Setting the position on the last element
  • Retrieving the element selected in a List Box control
  • Retrieving the index of the selected element
  • Getting the value of the selected element
  • Iterating over the elements of a List Box control
  • Properties specific to List Box controls
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Overview
WINDEV, WEBDEV and WINDEV Mobile allow you to programmatically handle List Box controls. To do so, use the variable of the List Box control in the code. This variable is of type numeric.
The variable of the List Box control:
  • corresponds to the name of the List Box control.
  • is initialized with the index of the element selected in the control.
To handle an element of the List Box control, use the following notation:
<List Box control> [<Element index>]
Remark: There are multiple WLanguage functions specific to List Box controls. For more details, see functions for handling List Box controls.
Initializing a List Box control

Initializing an element

To initialize an element in a List Box control, use ListAdd.
Remark: To modify an element in a List Box control, use the following syntax:
<List Box control>[Index] = <Value>
For example:
// Add elements
ListAdd(LIST_LIST1, "MOORE")
ListAdd(LIST_LIST1, Cust_Name)
// Modify elements
LIST_LIST1[3] = "MOORE"

Populating a List Box control

To initialize a List Box control, simply use an iteration loop to initialize all the elements in the control.
Index is int
FOR Index = <Start position> TO <End position>
ListAdd(<List Box control>, <Value>)
END
Example:
i is int
FOR i = 1 TO 52
ListAdd(LIST_LIST1, NAME[i])
END
Selecting an element in a List Box control

Selecting a row

To select the element at row <Index>, use:
  • the direct assignment:
    <List Box control> = Index
  • the ListSelectPlus function:
    ListSelectPlus(<List Box control>, <Index>)

Setting the position on the last element

To set the position on the last element of the List Box control, use:
  • the Count property:
    <List Box control>.Count
  • ListSelectPlus associated with the Count property:
    ListSelectPlus(<List Box control>, <List Box control>.Count)
  • the ListCount function:
    ListCount(<List Box control>)
Retrieving the element selected in a List Box control

Retrieving the index of the selected element

To retrieve the index of the selected element, use one of the following syntaxes:
  • directly read the element:
    Index = <List Box control>
  • the ListSelect function:
    Index = ListSelect(<List Box control>)
Remark: For multi-selection List Box controls, ListSelect is used to retrieve the selected elements.
// Retrieve the elements of a multi-selection List Box control
Rank is int = 0  // selection number
Index is int = 0  // index of the selected element
LOOP
Rank = Rank + 1
Index = ListSelect(LIST_LIST1, Rank)
IF Index = - 1 THEN BREAK
END

Getting the value of the selected element

To retrieve the value of selected element, use one of the following syntaxes:
  • Syntax 1:
    Index is int = <List Box control>
    <Variable> = <List Box control>[Index]
  • Syntax 2:
    <Variable> = <List Box control>[<List Box control>]
  • Syntax 3: DisplayedValue property (in server code only)
    Variable> = <List Box control>[Index].DisplayedValue
Caution: The stored value can be different from the displayed value. To get the stored value corresponding to one of the rows in the List Box control, use the StoredValue property.
Iterating over the elements of a List Box control
The FOR EACH statement performs different types of iterations on List Box controls:
  • Iterating over the elements in the control. The following syntax is used:
    FOR EACH ROW [<Index> [, <Counter>]] OF <List Box control>
     ...
    END
    where:
    • <Index>: Optional Integer variable. For each iteration, contains the index of the current row.
    • <Counter>: Optional Integer variable. This variable counts the number of iterations.
  • Iterate over the selected elements. The following syntax is used:
    FOR EACH SELECTED ROW [<Index>, [<Counter>]] OF <List Box control>
       ...
    END
    where:
    • <Index>: Integer variable. For each iteration, contains the index of the current selected row.
    • <Counter>: Optional Integer variable. This variable counts the number of iterations (number of selected rows for example).
Properties specific to List Box controls
The following properties are specific to List Box controls:
All types of List Box controls
HorizontalAlignmentGets and sets the horizontal alignment of the elements in the List Box control.
LineHeightGets and sets the height of the rows in a List Box control.
MemoryIndicates if the specified List Box control is populated programmatically or is based on a data file.
CountGets the number of rows in a List Box control.
FillTypeIndicates how a control is populated (programmatically, from a data file or from a variable). Applies to Table, List Box, ListView, Combo Box and Looper controls.
DisplayedValueGets the value of the current row or the value of a specific row in the List Box control.
StoredValueGets the value currently stored when selecting a row in the List Box control.
EmptyIndicates if a List Box control is empty.
List Box control populated programmatically only
InitialContentGets the initial content of a List Box control populated programmatically.
SortedIndicates if a List Box control populated programmatically is sorted, or sorts the control.
List Box control based on a data file only
BrowsedFileGets or sets the data file or query used to display records in List Box controls.
AutoBrowseIndicates if a List Box control is looped through automatically or programmatically.
DisplayedItemGets and sets the item displayed in a List Box control.
StoredItemGets and sets the stored item of a List Box control.
BrowsedItemGets and sets the item used to automatically loop through List Box controls.

For a complete list of WLanguage properties that can be used with a List Box control, see Properties associated with List Box controls.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 11/07/2022

Send a report | Local help