Dynamically Assigning Icons in a List View

Use the Image property of the CurrentItem in a list view to dynamically assign it an icon.

This example fills a list view with the employee details.  An icon is displayed for the selected employee in the list view. 

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(346) LEFT(381) TOP(135) WIDTH(549)

DEFINE_COM class(#PRIM_LTVW) name(#EMPLIST) DISPLAYPOSITION(1) FULLROWSELECT(True) HEIGHT(285) LEFT(8) PARENT(#COM_OWNER) SELECTIONSTYLE(Single) TABPOSITION(1) TOP(16) WIDTH(529)

DEFINE_COM class(#PRIM_LVCL) name(#LVCL_1) DISPLAYPOSITION(1) PARENT(#EMPLIST) SOURCE(#EMPNO) WIDTH(22)

DEFINE_COM class(#PRIM_LVCL) name(#LVCL_2) DISPLAYPOSITION(2) PARENT(#EMPLIST) SOURCE(#SURNAME) WIDTH(25)

DEFINE_COM class(#PRIM_LVCL) name(#LVCL_3) DISPLAYPOSITION(3) PARENT(#EMPLIST) SOURCE(#GIVENAME) WIDTH(33)

DEFINE_COM class(#PRIM_LVCL) name(#LVCL_4) DISPLAYPOSITION(4) PARENT(#EMPLIST) SOURCE(#SALARY) WIDTH(18)

EVTROUTINE handling(#com_owner.Initialize)

SELECT fields(#EMPLIST) from_file(PSLMST)

ADD_ENTRY to_list(#EMPLIST)

ENDSELECT

ENDROUTINE

EVTROUTINE handling(#EMPLIST.ItemGotSelection) options(*NOCLEARMESSAGES *NOCLEARERRORS)

SET com(#EMPLIST.CURRENTITEM) IMAGE(#VI_EMPLOY)

ENDROUTINE

EVTROUTINE handling(#EMPLIST.ItemLostSelection) options(*NOCLEARMESSAGES *NOCLEARERRORS)

SET com(#EMPLIST.CURRENTITEM) IMAGE(*NULL)

ENDROUTINE

END_COM