Step 1. Read Sorted List Items

In this step you will add push buttons with Click events which demonstrate how ListView1 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.  Select the form iiiListBasics on the Favorites/Last Opened tab and use the context menu to create a Copy:

     Name: iiiListBasicsB

     Description: List Basics Part B

      The new form will open at the Design tab with the form selected.

2.  Select the Layout ribbon and click on Rows to select Add Row:

3.  As the Status Bar is attached the bottom of the form, this will now be Row4 and a new Row3 is added above it:

4.  Drag the row dividers so your form looks like the following:

5.  Drag two push buttons into Row 3 and set them up as follows:

a.  Change Alignment to Center Left and Flow to Right

b.  Give each button a margin Left of 10

     Your design should look like the following:

6.  Select Button1 and change Caption to Read Sorted List and Name to SORTED. Create a Click event.

7.  Select Button2 and change Caption to Read Unsorted List and Name to UNSORTED. Create a Click event.

8.  Adjust the width of each button as necessary.

9.  Select the employee list (ListView1).

a.  On the Repository tab, locate the table xEmployee and expand its definition.

b.  Drag field xEmployeeIdentification into ListView1. The new column will currently be selected in the editor.

c.  Select the Details tab and change the Visible property to false.

10. In order to read the list entries in their sorted order we need to use a For/EndFor loop. The For statement returns each list entry as an object named by the Each() parameter.

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

For Each(#item) In(#ListView1.items)

Change Field(#STD_NUM) To(#item.entry)

Get_Entry Number(#STD_NUM) From_List(#ListView1)

Message Msgtxt('Employee ' + #xEmployeeIdentification + ' ' + #xEmployeeSurname + ' ' + #xEmployeeGivenNames)

Endfor

 

     Press F2 on the List View component to discover all its Properties, Events and Methods:

     The Item object defined by the Each(#Item) parameter: For Each(#item) In(#ListView1.items), has the same Properties, Events and Methods as CurrentItem. The Items property is a collection of list view items.

     On the Features tab as shown above, Expand Items / Properties to locate Item. Expand Item / Properties to find Entry.

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

11 To read the list entries in unsorted order (the order in which they were initially loaded) we need to use a Selectlist/Endselect loop.

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

Selectlist Named(#ListView1)

Message Msgtxt('Employee ' + #xEmployeeIdentification + ' ' + #xEmployeeSurname + ' ' + #xEmployeeGivenNames)

Endselect 

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

a.  Note the initial sequence of entries in the Surname column

b.  Messages output by the Read Sorted List push button, will be in the order currently displayed. You will see the messages sequence is the same as the sorted list view.

c.  Messages output by the Read Unsorted List push button, will always be in the loaded order. You'll see the sequence of messages is the same as the initially loaded list view.