Step 2 Create the Monthly Command Handler

VLF Windows Application Development

Step 2. Create the Monthly Command Handler

VFW106 – Using a List Collection

1.  Create a new Reusable Part / Panel:

     Name: iiiVFW32

     Description: Monthly Command Handler for Reports

2.  Give the reusable part an ancestor of VF_AC010

3.  Use the Design ribbon to give iiiVFW32 an Attachment manager.

4.  Add a List View to the center of the Panel. Change the List View Name property to EMP_VIEW.

5.  Create an Initialize event for EMP_VIEW.

6.  Locate the file PSLMST on the Repository tab and drag the fields EMPNO, SURNAME, GIVENAME and SALARY onto the list.

7.  Open the Source tab and define a key collection of employee objects, iiiVFW31 keyed by EMPNO

Define_Com Class(#PRIM_KCOL<#iiivfw31 #EMPNO>) Name(#EMPLOYEES) Style(Collection)

 

8. Add logic to the Initialize event for EMP_VIEW to populate the list view with all records from file PSLMST.

Clr_List Named(#EMP_VIEW)
Select Fields(#EMP_VIEW) From_File(pslmst)
Add_Entry To_List(#EMP_VIEW)
Endselect
 

9.  Add a Set_Ref to create an entry of iiiVFW31 to the keyed collection, for each employee, keyed by EMPNO, setting the properties of the employee object for each employee.

     The new code is highlighted in red.

Clr_List Named(#EMP_VIEW)
Select Fields(#EMP_VIEW) From_File(pslmst)
Add_Entry To_List(#EMP_VIEW)
Set_Ref Com(#EMPLOYEES<#EMPNO>) To(*CREATE_AS #IIIVFW31)
#EMPLOYEES<#EMPNO>.UEMPLOYEENUMBER := #EMPNO

#EMPLOYEES<#EMPNO>.UEMPLOYEEGIVENAME := #GIVENAME

#EMPLOYEES<#EMPNO>.UEMPLOYEESURNAME := #SURNAME

#EMPLOYEES<#EMPNO>.UEMPLOYEESALARY := #SALARY

Endselect
 

10. Create a method routine, SelectionChanged which will be called each time a list view entry is selected or loses selection.

     The routine should:

a.  Define a list collection of the employee object iiiVFW31. This will be used to store a list of the currently selected employees.

b.  Read through the list view using Selectlist

c.  Go straight to read the next list view entry, if it is not currently selected, using the Continue statement.

d.  Insert an entry to the list collection, from the keyed collection EMPLOYEES

     Your code should look like the following:

Mthroutine Name(SelectionChanged)
Define_Com Class(#PRIM_LCOL<#iiivfw31>) Name(#SELECTION)
Selectlist Named(#EMP_VIEW)
Continue If(*Not #EMP_VIEW.CURRENTITEM.SELECTED)
#SELECTION.INSERT( #EMPLOYEES<#EMPNO> )
Endselect
* Show the selected employees form
Endroutine

 

     Note the comment line. You will create the selected employees form in the next step.

     The list collection is defined within the method routine and is destroyed when the routine ends.

11. In the Design view, select the list view and create event routines for ItemGotSelection and ItemLostSelection. Add code to each routine to invoke the SelectionChanged method.

     Your code should look like the following:

Evtroutine Handling(#EMP_VIEW.ItemGotSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#com_owner.SelectionChanged
Endroutine
Evtroutine Handling(#EMP_VIEW.ItemLostSelection) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#com_owner.SelectionChanged
Endroutine

 

12. Leave this reusable part open in the editor.