Filling a Tree View on Demand

Visual LANSA

Filling a Tree View on Demand

To fill in a tree view only when the user double-clicks on items, you need to test what level of the tree is being worked with and fetch the data in the ItemExpanding event in the tree view. (See the next section for information about the tree view properties).  This example retrieves the section and the employee information on demand:

When you use a dynamic tree view, set the ManageChildren property of the tree view to True.

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(405) LEFT(129) TOP(131) WIDTH(377)
DEFINE_COM class(#PRIM_TRVW) name(#TRVW_1) DISPLAYPOSITION(1) HEIGHT(345) LEFT(24) PARENT(#COM_OWNER) TABPOSITION(1) TOP(8) WIDTH(321)
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(#DEPTMENT #DEPTDESC) from_file(DEPTAB)
ADD_ENTRY to_list(#TRVW_1)
ENDSELECT
ENDROUTINE
 
EVTROUTINE handling(#TRVW_1.ItemExpanding)
CHANGE field(#STD_NUM) to('#TRVW_1.CURRENTITEM.LEVEL')
CASE of_field(#STD_NUM)
WHEN value_is('= 1')
SELECT fields(#SECTION #SECDESC) from_file(SECTAB) with_key(#DEPTMENT)
ADD_ENTRY to_list(#TRVW_1)
ENDSELECT
WHEN value_is('= 2')
SELECT fields(#EMPNO #SURNAME) from_file(PSLMST1) with_key(#DEPTMENT #SECTION)
ADD_ENTRY to_list(#TRVW_1)
ENDSELECT
ENDCASE
 ENDROUTINE
 
END_COM

 

Ý 6.15.4 Tree View