Filling a Drill Down Tree View

A drill down tree only includes items that contain other items. To fill a drill down tree, use a single SELECT statement to retrieve all the fields. Data from other files is fetched as required. This example fills a three-level tree view of departments, sections, and employees from the PSLMST file. It shows all sections that contain employees and all departments which contain sections.

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) FORMPOSITION(ScreenCenter) LEFT(444) TOP(128) WIDTH(342)

DEFINE_COM class(#PRIM_TRVW) name(#TRVW_1) DISPLAYPOSITION(1) HEIGHT(289) LEFT(24) PARENT(#COM_OWNER) TABPOSITION(1) TOP(8) WIDTH(289)

DEFINE_COM class(#PRIM_TVCL) name(#TVCL_1) KEYPOSITION(1) LEVEL(1) PARENT(#TRVW_1) SOURCE(#DEPTMENT) VISIBLE(False)

DEFINE_COM class(#PRIM_TVCL) name(#TVCL_3) KEYPOSITION(1) LEVEL(2) PARENT(#TRVW_1) SOURCE(#SECTION) VISIBLE(False)

DEFINE_COM class(#PRIM_TVCL) name(#TVCL_2) DISPLAYPOSITION(1) IMAGE(#VI_DEPTCL) IMAGEEXPANDED(#VI_DEPTOP) LEVEL(1) PARENT(#TRVW_1) SOURCE(#DEPTDESC)

DEFINE_COM class(#PRIM_TVCL) name(#TVCL_4) DISPLAYPOSITION(1) IMAGE(#VI_SECTCL) IMAGEEXPANDED(#VI_SECTOP) LEVEL(2) PARENT(#TRVW_1) SOURCE(#SECDESC)

DEFINE_COM class(#PRIM_TVCL) name(#TVCL_5) KEYPOSITION(1) LEVEL(3) PARENT(#TRVW_1) SOURCE(#EMPNO) VISIBLE(False)

DEFINE_COM class(#PRIM_TVCL) name(#TVCL_6) DISPLAYPOSITION(1) LEVEL(3) PARENT(#TRVW_1) SOURCE(#SURNAME)

EVTROUTINE handling(#TRVW_1.Initialize) options(*NOCLEARMESSAGES *NOCLEARERRORS)

SELECT fields(#EMPNO #SURNAME #DEPTMENT #SECTION) from_file(PSLMST)

FETCH fields(#DEPTDESC) from_file(DEPTAB) with_key(#DEPTMENT)

FETCH fields(#SECDESC) from_file(SECTAB) with_key(#DEPTMENT #SECTION)

ADD_ENTRY to_list(#TRVW_1)

ENDSELECT

ENDROUTINE

END_COM