Step 2 Complete Form iiiVFW11 Tree View with Columns

VLF Windows Application Development

Step 2. Complete Form iiiVFW11 - Tree View with Columns

VFW062 – A Tree View with Columns

1.  Create the Add_Departments method routine using the following code

Mthroutine Name(Add_Departments) Access(*private)
Define_Com Class(#prim_tvit) Name(#Department_item) Reference(*dynamic)
Select Fields(#Deptment #deptdesc) From_File(Deptab)
#std_code := DEP
#depnull := *null
#com_owner.Add_Entry I_Code(#deptment) I_Description(#deptdesc) O_Tree_Item(#Department_item) I_Type(#std_code) I_Addr(#std_textl) I_Zip(#postcode) I_Phone(#std_descs) I_Date(#iiiSTRDTE)
 
* Add the sections for the department
#com_owner.Add_Sections I_Parent_Item(#Department_item) I_Department(#deptment)
Endselect
Endroutine

 

     Ignore the Add_Sections is not . . . error. You will add this routine in a later step.

2.  Review the Add_Departments method routine:

  • A dynamic reference to a tree view item component (#Department_item) is defined (#prim_tvit)
  • The routine selects all records from table DEPTAB
  • A Group_By #DEPNULL is used to initialize fields in the tree
  • Invokes the Add_Entry method routine for each department
  • The Add_Entry is passed values for all tree columns
  • Add_Entry is also passed the type of level being added (I_Type)
  • The Add_Section method is invoked, to add all sections for each department.

3.  Create an Add_Sections method routine using the following code:

Mthroutine Name(Add_Sections) Access(*private)
Define_Map For(*input) Class(#prim_tvit) Name(#i_parent_item) Pass(*by_reference)
Define_Map For(*input) Class(#deptment) Name(#i_department)

Define_Com Class(#prim_tvit) Name(#Section_item) Reference(*dynamic)

Select Fields(#section #secdesc #secaddr1 #secaddr2 #secaddr3 #secpCODE #secphBUS) From_File(sectab) With_Key(#i_department)
#std_code := SEC
#iiiSTRDTE := *null
#std_textl := #secaddr1.trim + ', ' + #secaddr2.trim + ', ' + #secaddr3.trim
#com_owner.Add_Entry I_Code(#section) I_Description(#secdesc) O_Tree_Item(#Section_item) I_Parent_Item(#i_parent_item) I_Type(#std_code) I_Addr(#std_textl) I_Zip(#secpcode) I_Phone(#secphbus) I_Date(#iiiSTRDTE)
* Add the Employees for the section
#com_owner.Add_Employees I_Parent_Item(#Section_item) I_Department(#deptment) I_Section(#Section)
Endselect

* Set a margin on the last item to help separate the groups of tree items
#Personnel.Currentitem.marginbottom := 5
Endroutine

 

     Ignore the Add_Employees is not . . . error, which you will correct later.

4.  Review the Add_Sections method routine logic:

  • A dynamic reference to a tree view component (#Section_item) is defined.
  • Records are selected from the table SECTAB, for the received department code i_department.
  • The Add_Entry method routine is invoked for each section record retrieved.
  • The section level populates all columns, except Date, which is initialized as *Null.
  • The i_parent_item is passed by reference. This is the department tree view item.
  • For each section the Add_Employee method is invoked to add employees for each department / section.
  • A reference to the section tree view item is passed (#Section_item) to the Add_Employees method routine.
  • A MarginBottom property is set for current item, after employees for the section have been added.

5.  Create an Add_Employee method routine based on the following code:

Mthroutine Name(Add_Employees) Access(*private)
Define_Map For(*input) Class(#prim_tvit) Name(#i_parent_item) Pass(*by_reference)
Define_Map For(*input) Class(#deptment) Name(#i_Department)
Define_Map For(*input) Class(#section) Name(#i_Section)
 

Define_Com Class(#prim_tvit) Name(#Employee_item) Reference(*dynamic)
#std_code := EMP
 

Select Fields(#empno #givename #surname #address1 #address2 #address3 #postcode #phonebus #startdte) From_File(pslmst1) With_Key(#i_Department #i_Section)
#std_textl := #address1.trim + ', ' + #address2 + ', ' + #address3
#iiiSTRDTE := #startdte.asdate( DDMMYY ).asdisplayString( DDsMMsCCYY )
#com_owner.Add_Entry I_Code(#empno) I_Description(#Surname.trim + ', ' + #Givename) I_Parent_Item(#i_parent_item) O_Tree_Item(#Employee_item) I_Type(#std_code) I_Addr(#std_textl) I_Zip(#postcode) I_Phone(#phonebus) I_Date(#iiiSTRDTE)
Endselect
 

* Set a margin on the last item to help separate the groups of tree items
#Personnel.Currentitem.marginbottom := 5
Endroutine

 

     Use this code to create date field iiiSTRDTE if your date format is MMDDYY:

#iiiSTRDTE := #startdte.asdate( MMDDYY ).asdisplayString( DDsMMsCCYY )

     Note: Retrieving the real date field (STRDTER) and converting this using the following code, avoids the need for two versions of the code:

#iiiSTRDTE := #startdter.asdate( YYMMDD ).asdisplayString( DDsMMsCCYY )

6.  Review the Add_Employee method routine logic:

  • A dynamic reference to a tree view item Employee_item is defined.
  • Records are selected from the logical file PSLMST1 using the passed department and section codes (i_department and i_section).
  • Add_Employee populates all tree view columns.
  • Start Date is shown in an alpha column, so that it can be set to blank for the department and section levels.

7.  Complete the load push button click event. Your code should now look like the following. New code is highlighted in red, italic.

Evtroutine Handling(#pb_load.Click)
Clr_List Named(#Personnel)
#com_owner.Add_departments
Endroutine

 

8.  Review the Add_Entry method routine again.

Note:
  • The routine has an output parameter #o_tree_item which is a reference to the current tree view item
  •  After each row is added (add_entry to_list(#Personnel) a reference to the current tree view item is obtained via:

 Set Com(#Personnel.currentitem) Parentitem(#i_Parent_item)

 

  • This reference is returned to the calling method routine via:

 * Return the tree item for use as a parent 

 Set_Ref Com(#o_Tree_item) To(#Personnel.currentitem)

 

8.  Compile your form and test it.