Step 4. Fill the Tree View on Demand
VFW060 – Using a Tree View
The tree view is currently loaded with all department, section and employee data initially. Clearly this is an approach which will work well for a small amount of data. For your own applications, it is much more likely that you will need to populate the tree view "on demand". Your logic would add all records to level one, and then add to level two and three when a level is expanded (by click on the + next to that item).
In this step you will change your logic so that the tree view is populated on demand.
1. In the true.
view, select the tree view and change its property toThe help for this property (see
) will inform you:controls what happens when a tree item is collapsed.
The
property controls whether child items are automatically deleted when a tree item is collapsed. It will typically be used when the children are loaded during an event. It can be set to True or False.2. Create an
event handling routine for the tree view.3. Cut and paste the Select sections and select employees logic from the from the
event into the Tree view event handling routine.The form
logic should now only add department data to the tree initially.Your form
e should look like the following:Evtroutine Handling(#com_owner.Initialize)
Set Com(#com_owner) Caption(*component_desc)
Clr_List Named(#TRVW_1)
Select Fields(#DEPTMENT #DEPTDESC) From_File(deptab)
Add_Entry To_List(#TRVW_1)
Endselect
Endroutine
4. Like the level selected. Add the required logic re-using the code pasted from the form routine.
event routine, the event will need to perform the action required based on the- Assign TRVW_1.currentItem.Level to STD_NUM
- Within a Case loop for STD_NUM:
- For Level 1, select from the sections file for this department
- For Level 2, select from the employees file for this department / section.
- For Level 3, no action required.
Your code should now look like the following:
Evtroutine Handling(#TRVW_1.ItemExpanding) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#std_num := #TRVW_1.currentItem.level
Case (#std_num)
When (= 1)
Select Fields(#SECTION #SECDESC) From_File(sectab) With_Key(#DEPTMENT)
Add_Entry To_List(#TRVW_1)
Endselect
When (= 2)
Select Fields(#EMPNO #SURNAME #GIVENAME) From_File(pslmst1) With_Key(#DEPTMENT #SECTION)
#fullname := #SURNAME + ', ' + #GIVENAME
Add_Entry To_List(#TRVW_1)
Endselect
When (= 3)
* no action required
Endcase
Endroutine
5. Compile your form and test it. From an end user perspective it should work exactly the same as before.