List view columns can be sorted in ascending or descending order by setting the SortOnClick property of the columns to True.
This example fills a list view with employee number, name, salary and zip code details. The user can dynamically sort the list at any time by clicking on the heading of any column.
To see how the example works, copy this code and paste it to a form component:
FUNCTION options(*DIRECT)
BEGIN_COM role(*EXTENDS #PRIM_FORM) HEIGHT(330) LEFT(327) TOP(120) WIDTH(604)
DEFINE_COM class(#PRIM_LTVW) name(#EMPLIST) DISPLAYPOSITION(1) FULLROWSELECT(True) HEIGHT(285) LEFT(8) PARENT(#COM_OWNER) TABPOSITION(1) TOP(8) WIDTH(577)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_1) DISPLAYPOSITION(1) PARENT(#EMPLIST) SORTONCLICK(True) SOURCE(#EMPNO) WIDTH(18)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_2) DISPLAYPOSITION(2) PARENT(#EMPLIST) SORTONCLICK(True) SOURCE(#SURNAME) WIDTH(23)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_3) DISPLAYPOSITION(3) PARENT(#EMPLIST) SORTONCLICK(True) SOURCE(#GIVENAME) WIDTH(25)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_4) DISPLAYPOSITION(4) PARENT(#EMPLIST) SORTONCLICK(True) SOURCE(#SALARY) WIDTH(16)
DEFINE_COM class(#PRIM_LVCL) name(#LVCL_5) DISPLAYPOSITION(5) PARENT(#EMPLIST) SORTONCLICK(True) SOURCE(#POSTCODE) WIDTH(18)
EVTROUTINE handling(#com_owner.Initialize)
SELECT fields(#EMPLIST) from_file(PSLMST)
ADD_ENTRY to_list(#EMPLIST)
ENDSELECT
ENDROUTINE
END_COM