In this step, you will modify the new web page to initially load departments only to the List control. Employees and Employee Notes will be added when the level above is expanded. You will remove code which loads employees for each department added and loads employees notes for each employee loaded to the List control.
An event handling routine for the List.ItemExpanding will test the level being expanded and load employees and employee notes as appropriate.
Note: All Departments, Employees and Employee Notes data will be loaded from the server by the web page's CreateInstance event routine. When these data sets are very large, we would change the data retrieval logic, to load a list of all Departments from the server initially, and then retrieve Employees for this Department from the server, when this level in the tree is expanded.
1. On the Design tab, select the List component and on the Details / Events tab double click on ItemExpanding to create an event handling routine.
2. With the List component selected, press F2 to display Features tab. Note that the ItemExpanding event can be expanded to show it has an Item parameter. Double click to display detailed Help in a browser window which explains that Item() passes a reference for the current list item.
3. Switch to the Source tab. Add an Item parameter to the List.ItemExpanding event definition. New code is highlighted
Evtroutine Handling(#List.ItemExpanding) Item(#ThisItem)
Endroutine
Note: Item(#ThisItem) is a reference to the list item being expanded and will provide access to any properties your routine may require.
4. Complete the List.ItemExpanding event routine by adding code to perform the following:
When defining this event logic, recall that the first column in the list is based on field STD_OBJ. Depending on the level in the tree, this field will contain department code or employee ID.
Check to see that the list has not been previously populated by checking ThisItem.ItemCount is equal to zero.
Define a CASE/ENDCASE loop for the value of ThisItem.level
When level = 1:
Assign xDepartmentCode to the value STD_OBJ.
Invoke the LoadEmployees method passing the values xDepartmentCode and ThisItem.
When level = 2:
Assign xEmployeeIdentification to the value of STD_OBJ.
Invoke LoadNotes passing the values xEmployeeIdentification and ThisItem
End Case
End If
Your code should look like the following:
Evtroutine Handling(#List.ItemExpanding) Item(#ThisItem)
If (#ThisItem.ItemCount = 0)
Case Of_Field(#ThisItem.Level)
When (= 1)
#xDepartmentCode := #STD_OBJ
#com_self.LoadEmployees( #xDepartmentCode #ThisItem )
When (= 2)
#xEmployeeIdentification := #std_obj
#COM_SELF.LoadNotes( #xEmployeeIdentification #ThisItem )
Endcase
Endif
Endroutine