How to create a tree view with a different background colour
for each level
| Date: |
2nd September 2009 |
| Product/Release: |
Visual LANSA SP5 (RDMLX) |
| Abstract: |
How to create a tree view with a different background
colour for each level |
| Submitted By: |
LANSA Technical Support |
Description:
In order to achieve this the ViewStyle property of the tree is
used. When this is set to unlevelled, the effect is columnar
trees as seen in the LANSA IDE.
The below code produces the following example.

Solution:
The sample code below displays this effect. Simply copy and
paste into a form compile and run.
Function Options(*DIRECT)
BEGIN_COM ROLE(*EXTENDS #PRIM_FORM) CLIENTHEIGHT(500) CLIENTWIDTH(528) HEIGHT(534)
LAYOUTMANAGER(#ATLM_1) LEFT(499) TOP(151) WIDTH(536)
DEFINE_COM CLASS(#PRIM_ATLM) NAME(#ATLM_1)
DEFINE_COM CLASS(#PRIM_ATLI) NAME(#ATLI_1) ATTACHMENT(Center) MANAGE(#Tree) PARENT(#ATLM_1)
DEFINE_COM CLASS(#PRIM_TRVW) NAME(#Tree) COLUMNBUTTONHEIGHT(18) COMPONENTVERSION(2)
DISPLAYPOSITION(1) FULLROWSELECT(True) HEIGHT(500) LEFT(0) PARENT(#COM_OWNER) TABPOSITION(1)
TOP(0) VIEWSTYLE(UnLevelled) WIDTH(528)
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_1) LEVEL(1) PARENT(#Tree) SOURCE(#DEPTMENT) VISIBLE(False)
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_2) LEVEL(1) PARENT(#Tree) SOURCE(#SECTION) VISIBLE(False)
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_3) LEVEL(1) PARENT(#Tree) SOURCE(#EMPNO) VISIBLE(False)
DEFINE_COM CLASS(#PRIM_TVCL) NAME(#TVCL_4) DISPLAYPOSITION(1) LEVEL(1) PARENT(#Tree)
SOURCE(#STD_QSEL) WIDTHTYPE(Remainder)
Evtroutine Handling(#Com_owner.CreateInstance)
#Com_owner.AddDepartments
Endroutine
Mthroutine Name(AddDepartments)
Select Fields(*All) From_File(Deptab)
#Com_owner.AddEntry( #Deptdesc #UF_VS004 )
#Com_Owner.AddSections( #Tree.Currentitem )
Endselect
Endroutine
Mthroutine Name(AddSections)
Define_Map For(*Input) Class(#prim_tvit) Name(#ParentItem) Pass(*by_reference)
Select Fields(*All) From_File(Sectab) With_Key(#Deptment)
#Com_owner.AddEntry( #Secdesc #UF_VS002 #ParentItem )
#Com_Owner.AddEmployees( #Tree.Currentitem )
Endselect
Endroutine
Mthroutine Name(AddEmployees)
Define_Map For(*Input) Class(#prim_tvit) Name(#ParentItem) Pass(*by_reference)
Select Fields(*All) From_File(Pslmst1) With_Key(#Deptment #Section)
#Com_owner.AddEntry( (#GiveName + " " + #Surname) #VF_VS104 #ParentItem )
Endselect
Endroutine
Mthroutine Name(AddEntry) Access(*private)
Define_Map For(*Input) Class(#prim_alph) Name(#Text)
Define_Map For(*Input) Class(#prim_vs) Name(#VisualStyle) Pass(*by_reference)
Define_Map For(*Input) Class(#prim_tvit) Name(#ParentItem) Mandatory(*null) Pass(*by_reference)
Define_Map For(*Result) Class(#prim_tvit) Name(#Result) Mandatory(*null) Pass(*by_reference)
#Std_qsel := #Text
Add_Entry To_List(#Tree)
#Tree.Currentitem.VisualStyle <= #VisualStyle
#Tree.Currentitem.ParentItem <= #ParentItem
#Result <= #Tree.Currentitem
Endroutine
End_Com
|