You’ve probably used the LISTBOX SELECT ROW command many times, looping through each entity in order to select the rows for an entity selection. 4D v18 R3 simplifies the process with the new LISTBOX SELECT ROWS command.
HDI: Examples to easily select rows in a list box
entity selection List box
The new LISTBOX SELECT ROWS command accepts an entity selection as a parameter. Rows matching the entity selection can be selected with just a single line of code. They can also easily be added to or removed from the selected rows.
Example
The following code creates an entity selection of cash-paying clients and selects the rows for the entity selection in a list box:
C_OBJECT($selection)
$selection:=ds.Invoices.query("payment=:1";"Cash")
LISTBOX SELECT ROWS(*;"Invoices";$selection;lk replace selection)
Here’s the resulting list box:
Collection List box
The new LISTBOX SELECT ROWS command uses the same, easy principle! Simply, pass a collection containing the objects references you want to select to the command.
Example
The following code uses the Form.payments collection and selects the rows for clients within a specified payment range:
Using the Form.payments collection:
[ {name:Cash,min:100,max:500}, {name:Cheque,min:200,max:1200}, {name:Credit card,min:700,max:1500}, {name:Gift card,min:800,max:900} ]
C_COLLECTION($collection)
$collection:=Form.payments.query("min <= :1 and max >= :1";250)
LISTBOX SELECT ROWS(*;"Payments";$collection;lk replace selection)
The resulting list box:
Download the HDI above and check the doc center to learn more about this new command.