KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Sorting Collection or Entity Selection Based Listbox
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: January 17, 2022

Listboxes with some data types, like arrays, allow automatic sorting of the columns when clicking on the associatated header.

With collection or entity selection based listboxes, the ordering of the rows are based on the source. A method to order these types of listboxes is to use the On Header Click event. This event has been updated in v19 to now return the associated column object's name and the column number in the detailed Form event command. The new information allows multiple ways to identify which column's header was clicked allowing a method to run and sort the rows by the specified column.

For example if the column names were based on the field names of the entity selection the code could look something like the following:

C_OBJECT($eventObj)
$eventObj:=Form Event

If($eventObj.code=On Header Click)
   lbEntSel.orderby($eventObj.columnName)
End if