Step 2 Complete the Command Handler logic

VLF Windows Application Development

Step 2. Complete the Command Handler logic

VFW056 – Process a List in Sorted Order

1.  Add code to the PHBN_LOADED click event routine, which:

a.  Clears the list view LIST_2

b.  Selects all items in LIST_1 using SELECTLIST

c.  If LIST_1 current item, selected is true, add an entry to LIST_2

     For example:

Evtroutine Handling(#PHBN_LOADED.Click)
Clr_List Named(#LIST_2)
Selectlist Named(#LIST_1)
If (#LIST_1.currentItem.selected)
Add_Entry To_List(#LIST_2)
Endif
Endselect
Endroutine

 

2.  Add code to the PHBN_SORTED Click event routine which:

a.  Clears the list LIST_2

b.  Processes all items in LIST_1 using a FOR/ENDFOR loop. For example:

Evtroutine Handling(#PHBN_SORTED.Click)
Clr_List Named(#LIST_2)
For Each(#row) In(#LIST_1.items)
. . . .
Endfor
Endroutine

 

LIST_1.Items returns a reference to the Items collection in the list view component.

Within the FOR/ENDFOR loop, each item will be referred to as #ROW

c.  Retrieve each list item using GET_ENTRY.  For example

Evtroutine Handling(#PHBN_SORTED.Click)
Clr_List Named(#LIST_2)
For Each(#row) In(#LIST_1.items)
Get_Entry Number(#row.entry) From_List(#LIST_1)
Endfor
Endroutine

 

     Row.Entry is the entry number for each list item

d.  If the item is selected, add an entry to LIST_2. For example

Evtroutine Handling(#PHBN_SORTED.Click)
Clr_List Named(#LIST_2)
For Each(#row) In(#LIST_1.items)
Get_Entry Number(#row.entry) From_List(#LIST_1)
If (#row.Selected)
Add_Entry To_List(#LIST_2)

Endif

Endfor
Endroutine

 

3.  Compile your command handler.

4.  Execute the Framework as a Designer and open the properties dialog for the Reports business object and select the Commands Enabled tab.

     Select the Sort action and define its Windows command handler component as iiiVFW09.

5.  Save and Restart the Framework.

6.  Test the Sort command handler for the Reports business object.

a.  Right click on the Weekly command tab and select the Sort action from the context menu.

     Note that initially the left hand employee list is displayed in its loaded order.

b.  Without sorting on a column in the left hand list, select some entries and use the Loaded Order button. The right hand list should now contain the selected entries as they are displayed on the left, which is their loaded order.

c.  Test the results using the Loaded Order and Sorted Order buttons. The right hand list should contain the same selected entries in each case.

d.  Sort the left hand list on Surname. Select entries and test the Loaded Order button. Note that the right hand list contains entries from their loaded position, which is no longer the same as the displayed list.

e.  Now try the Sorted Order button and note that the right hand list now contains the same entries as displayed and selected in the left hand list. The list has been processed in its sorted order.