Step 4 Build a Static Working List of Selected Items

VLF Windows Application Development

Step 4. Build a Static Working List of Selected Items

VFW052 – Build a Working List of Selected Items

In this step you will extend the Weekly command handler, by defining a second working list, STATIC.

This list is called STATIC because when a button is clicked, the whole list view is read and currently selected items are selected, to build the STATIC list. Its entries are not maintained dynamically each time a list item gets or loses selection.

A Static Save push button click event will then process the List view adding only the selected items to the STATIC working list.

TRANSFORM_LIST will be used to save the STATIC working list as comma separated file.

1.  Define a work field STATCOUNT with reference to field LISTCOUNT

2.  Define a working list, named STATIC containing EMPNO, SURNAME, GIVENAME and SALARY. Set entries to *MAX and a Counter of STATCOUNT.

     Your code should look like the following:

Define Field(#statcount) Reffld(#listcount)
Def_List Name(#static) Fields(#empno #surname #givename #salary) Counter(#statcount) Type(*working) Entrys(*max)

 

3.  Add a push button to the bottom panel (PANL_1). Change its name to PHBN_STAT and change Caption to Static Save.

4.  Create a Click event routine for push button PHBN_STAT which:

a.  Clears the static working list

b.  Reads all entries in the List View using SELECTLIST/ENDSELECT.

c.  Continues reading the next list view entry if the currentitem is not selected.

     Hint: Use Feature Help (F2) on the list view and examine properties to find currentitem and then the properties of currentitem.

d.  For each selected item, add an entry to the static working list.

e.  If STATCOUNT is greater than zero, use the TRANSFORM_LIST BIF to save to a CSV file.

f.  Test RETCODE and issue a success or error message as appropriate.

     Your code should look like the following:

Evtroutine Handling(#PHBN_STAT.Click)
Clr_List Named(#Static)
Selectlist Named(#LTVW_1)
Continue If(*Not #LTVW_1.currentitem.selected)
Add_Entry To_List(#Static)
Endselect
Use Builtin(transform_list) With_Args(#Static 'c:\temp\iiistatic.csv' O) To_Get(#retcode)
If (#retcode = OK)
Message Msgtxt('Static file saved to C:temp\iiistatic.csv')
Else
Message Msgtxt('Static file save failed')
Endif
Endroutine