Tree view HasChildren property

Date:Archived
Product/Release:Visual LANSA
Abstract:Tree view appearance
Submitted By:LANSA Support

All items added to a tree view have a property of HasChildren. By default, it will be set to 'unknown'. This means that when the item is displayed, the "+" will appear to the left. However, the user should not see the "+" if there are no associated child items.

Below is a simple example of a tree showing department, section and employee data. When the user expands on a department, double click or click on the "+", the application reads the data for the next level.

When a section is expanded, the employee file is checked to see wether there are any employees in the section. If none are found, the HasChildren property is set to NO. This will prevent the appearance of the "+", indicating to the user that there are no child items.

As the item has no children, the tree assumes it to be the last item in the branch. This alters the way that the mouse DoubleClick is handled. When the HasChildren property is either YES or UNKNOWN, the ItemExpanding event will be fired, followed by the DoubleClick event. When it is the last item in the branch, only the DoubleClick event is fired.

See the source below.

FUNCTION OPTIONS(*DIRECT);
BEGIN_COM HEIGHT(371) LAYOUTMANAGER(#ATLM_1) LEFT(307) TOP(107) WIDTH(445);
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_1);
DEFINE_COM CLASS(#PRIM_TRVW) NAME(#TRVW_1) DISPLAYPOSITION(1) HEIGHT(344) LEFT(0) MANAGECHILDREN(True) PARENT(#COM_OWNER) TABPOSITION(1) TOP(0) WIDTH(437);
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_1) ATTACHMENT(Center) MANAGE(#TRVW_1) PARENT(#ATLM_1);
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_2) DISPLAYPOSITION(1) LEVEL(1) PARENT(#TRVW_1) SORTPOSITION(1) SOURCE(#DEPTDESC);
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_4) DISPLAYPOSITION(1) LEVEL(2) PARENT(#TRVW_1) SORTPOSITION(1) SOURCE(#SECDESC);
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_5) DISPLAYPOSITION(1) KEYPOSITION(1) LEVEL(3) PARENT(#TRVW_1) SORTPOSITION(1) SOURCE(#EMPNO);
;
* Load list before form appears on the screen;
EVTROUTINE handling(#com_owner.CreateInstance);
SET #com_owner caption(*component_desc);
* Set the icons;
set com(#tvcl_2) image(#vi_deptcl) imageexpanded(#vi_deptop);
set com(#tvcl_4) image(#vi_sectcl) imageexpanded(#vi_sectop);
set com(#tvcl_5) image(#vi_employ);
;
* Buildlist of Departments;
select fields(#deptment #deptdesc) from_file(deptab);
add_entry to_list(#trvw_1);
;
* check for children;
CHECK_FOR IN_FILE(SECTAB) WITH_KEY(#DEPTMENT);
if_status is(*notequalkey);
set com(#trvw_1.currentitem) haschildren(no) ;
endif;
endselect;
ENDROUTINE;
;
* On Expansion of the list;
EVTROUTINE HANDLING(#TRVW_1.ItemExpanding) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
define field(#level) reffld(#std_num);
change field(#level) to(#trvw_1.currentitem.level);
;
* If expanding a department;
if cond('#level = 1');
select fields(#section #secdesc) from_file(sectab) with_key(#deptment);
add_entry to_list(#trvw_1);
;
* Check for employees ina a section.  If none found, do not display the "+";
Check_For In_File(PSLMST1) With_key(#deptment #section);
if_status is(*notequalkey);
set com(#trvw_1.currentitem) haschildren(no) ;
endif;
endselect;
endif;

* If expanding a Section;
if cond('#level = 2');
select fields(#empno) from_file(pslmst1) with_key(#deptment #section);
add_entry to_list(#trvw_1);
endselect;
endif;
ENDROUTINE;
;
* On collapse;
EVTROUTINE HANDLING(#TRVW_1.ItemCollapsed) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS);
set com(#trvw_1.currentitem) haschildren(unknown);
ENDROUTINE;
END_COM;