Starting with 4D v17, the content of a multilevel collection can easily be displayed in different list boxes. Meaning that you can bind several list boxes to display nested details … without a single line of code! This can be achieved by simply using an object or a collection as the data source for another list box!
With the new list box collection type, the “Current item” and “Selected items” properties have been added. Keep in mind that the “Current item” property allows you to get an object, while the “Selected item” property returns a collection.
Let’s checkout a concrete example and see how we can display the results of a blood test!
What’s in?
At the first level, we have the patient’s name, the date of the exam, and the name of the doctor. Then, the results are classified by category. For each category, there is a list of tests with the result value, the min, the max, and the unit.
In terms of data structure, we have an object with some first-level attributes (i.e. firstname, lastname, etc.), as well as a collection of category objects. Then for each category object, we have a collection of test objects. To summarize:
{ "lastname": "Beal", "firstname": "Estele", ..., "results": [{ "category": "Metabolic", "test": [ { "name": "Albumin", "value": ... }, { "name": ... }] }, { "category": "Lipoprotein", "test": [ { "name": "HDL", "value": ... }, { "name": ... }] }, {...}] }
The schema below describes how the results are displayed in two list boxes beside the object input. All this … without a single line of code! In fact, all properties are defined in the form objects, the only part where some coding is needed is when loading the result. That’s it, folks! ?
As you can see, this example makes blood test results easier to read and understand, especially when the incorrect data is highlighted with a splash of color.
To do this, we associated the following Decorate method with the meta expression in the list box property:
If (This.value>(This.max*2))
$0:=Form.meta.doubleOutOfRange
Else
If ((This.value>This.max) | (This.value<This.min))
$0:=Form.meta.outOfRange
Else
$0:=Form.meta.perfectValue
End if
End if