Step 7 Read Sorted List Items optional

Visual LANSA

Step 7. Read Sorted List Items (optional)

FRM055 - List Component Basics

In this step you will add push buttons with Click events which demonstrate how the List View EMPLOYS can be processed to retrieve the sorted list, or the list in its original order. That is, in the order in which it was loaded.

1.  Lengthen the form and drop a Status bar at the bottom of the form. This will be used to display messages output by the list processing

2.  Add a push button below the list view.

a.  Change its Caption to Read Sorted List.

b.Change it's Name to SORTED.

c.  Create a Click event routine for the SORTED push button.

d.  Add the following code to the SORTED.Click event handling routine:

For Each(#item) In(#EMPLOYS.items)
Change Field(#STD_NUM) To(#item.entry)
Get_Entry Number(#STD_NUM) From_List(#EMPLOYS)
Message Msgtxt('Employee ' + #EMPNO + ' ' + #Surname + ' ' + #givename)
Endfor

 

     The FOR loop will read all items in the list EMPLOYS. That is, all rows, in sorted order.

     You can use F2 Feature help on the List View component to discover all its Properties, Events and Methods:

     The Item object defined by the For Each(#Item) . . . . in the above code, has the same Properties, Events and Methods as CurrentItem.

     You can use F2 Feature help on the List View component. Expand the CurrentItem property  and double click on the PRIM_LVIT object to show the Properties, Events and Methods for CurrentItem:

     Note also that you can use the Auto Complete prompter (Ctrl + Space if the prompter is currently turned off in Editor Settings) in the editor to discover the properties for Item:

3.  Add a second push button below the EMPLOYS list view.

a.  Change its Caption to Read Unsorted List.

b. Change its Name to UNSORTED.

c.  Create a Click event for UNSORTED

d.  Add the following code to the UNSORTED.Click event handling routine:

Selectlist Named(#EMPLOYS)
Message Msgtxt('Employee ' + #EMPNO + ' ' + #Surname + ' ' + #givename)
Endselect

 

     The SELECTLIST reads the List View EMPLOYS in its unsorted sequence. That is, in the order in which the list was loaded.

     Your form should look like the following:

4.  Compile and test your form. Sort the list by clicking on the column heading for Surname, Given Name or Post Code.

a.  Messages output by the Read Sorted List push button, will be in the order currently displayed. Compare employee numbers with the list view.

b.  Messages output by the Read Unsorted List push button, will always be in the loaded order. In this case in Employee Number sequence.