KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Displaying different data types in a single column on a listbox - revised
PRODUCT: 4D | VERSION: 15 | PLATFORM: Mac & Win
Published On: February 15, 2017

In v15, array based listbox columns can be an object array. An object array will allow the each element in the array to be its own data type (text, integer, boolean, etc...). The contents for each cell in the column are based off attributes in the corresponding object array. Each object in the array must contain at minimum the attribute: value type. The attribute name must be “valueType”.

Minimum object: {valueType:”text”}

The value for the attribute “valueType” can be set programmatically using OB SET. This attribute will determine the value type of the corresponding cell in the listbox.

To set the value to be displayed, in the cell, the object should also contain the attribute “value”. The data type can be different for each cell. Below is an example of a listbox with a column that contains values of different data type:



The columns in the listbox above (arrLabels, arrOB) were generated using the following code:

ARRAY TEXT(arrLabels;0)
ARRAY OBJECT(arrOB;0)
C_OBJECT($ob)

// Set values for Label Column
APPEND TO ARRAY(arrLabels;"Text")
APPEND TO ARRAY(arrLabels;"Integer")
APPEND TO ARRAY(arrLabels;"Real")
APPEND TO ARRAY(arrLabels;"Boolean")

// Set values for Value column
OB SET($ob;"valueType";"text";"value";"abc")
APPEND TO ARRAY(arrOB;$ob)
CLEAR VARIABLE($ob)

OB SET($ob;"valueType";"Integer";"value";123)
APPEND TO ARRAY(arrOB;$ob)
CLEAR VARIABLE($ob)

OB SET($ob;"valueType";"Real";"value";12.3333)
APPEND TO ARRAY(arrOB;$ob)
CLEAR VARIABLE($ob)

OB SET($ob;"valueType";"Boolean";"value";True)
APPEND TO ARRAY(arrOB;$ob)
CLEAR VARIABLE($ob)
LISTBOX INSERT COLUMN(LB;2;"ColName2";arrOB;"headerName2";headerVar)

Please note that this feature is a subset of the new 4D View Pro. Therefore, a 4D View license must be installed. For more information about using objects in listboxes, see documentation here.