Filling Listboxes and Comboboxes
Listboxes and comboboxes can be filled through the object inspector and/or through the code. Only if comboboxes are concerned, and the property "ReadOnly" is set to false, the filling can also be done manually by the end user. In all cases there will exist records with two separate types of data, which are:
-
Items that are displayed inside the box item.
-
Values that are used inside the program.
There are two different approaches for filling these controls through the code, either maintaining the content directly from memory or using a textfile for this. The value for the MemoryBased property determines which approach is supported by the control.
Through the Items and Values option in the object inspector, the initial Items and Values list for the listbox or combobox can be specified.
Note: These initial Items and Values will be overwritten when the concerned control is filled through a text file when MemoryBased is false or when changed in the code when MemoryBased is true.
Dynamic filling from memory
When the MemoryBased property is set to true, the control will be filled directly from memory, in one data-stream that is sent from the data server to the client. In the code, you must then use the ITEMS function. In most situations this way of dynamically filling listboxes or comboboxes be the most practical approach.
Dynamic filling through a text file
When the MemoryBased property is set to "False", listboxes and comboboxes use textfiles to read and write their data. The content file may contain more than 2 columns and therefore it is possible to specify multiple numbers for these properties. You can refer to the box parameters by using the properties "ItemsDisplayed" and "ValueSend". The "ItemsDisplayed" property contains the number(s) of the column(s) that contain(s) the text that is displayed in the box item when the record is selected at runtime. The "ValueSend" property contains the value that is internally used by the application when a record is selected. For example, if the ItemsDisplayed value is "1,3", the box item will display the data for the first and the third column of the data file.
If you add data with the FILLBOX command and no file for the listbox or combobox exists, a textfile named <Object name>.<layout control name> will therefore be created automatically when the item is used at runtime. This file is stored in the folder that is specified as Listboxes path on the ControlCenter screen "Basepaths".
When using the FILLBOX command, it is not necessary to refer to the data file in your code. However, to avoid the limitations and performance loss that might be caused by the use of FILLBOX, you can also refer directly to a databox file. This is possible with the ATTACHTOBOX command. To enable the filling of a data box at runtime, its ReadOnly property has to be set to "False".
When using listboxes and comboboxes with textfiles, it is also possible to use any other functionality that is available for reading and modifying textfiles.
The filling of a box through a text file always has to be done within a single transaction. If multiple lines have to be added, f.i. a FILLBOX instruction would be needed for each line. To fill the box at a later moment, you can empty the box by writing '' into this item. After that, the new content can be written into the box. In most cases, it may be useful to specify a FILLBOX within a loop. Always make sure that the type and length for the values that you want to add to the boxes are valid.