Skip to content

Sort_Items - DfBaseList

Sorts the items in a list in ascending or descending order

Type: Procedure

Parameters

Parameter Type Description
eDirection Integer ConstantMeaning

Syntax

Procedure Sort_Items Integer eDirection

Call Example

Send Sort_Items eDirection

Description

The items displayed in the list are sorted. After the sort, the current_item property is set to the top_item. Then the object is painted. If the keyword descending is used or the boolean descending is true, the sort is done descending (in reverse). If it is false or the ascending keyword is used, the sort is done ascending. Sorting is case sensitive (uppercase letters come before lowercase, rather than intermixed).

Procedure SortList
    send Sort_Items of oList Ascending
End_Procedure  // SortList

Sample

This sample show you how to create a List with information from the SQL Server Northwind sample database Customer table.

Object oCustomerList is a List
    Set Size to 193 180
    Set Location to 5 5
    Set peAnchors to anAll

    // Create a property with an array of RowId's
    Property RowId[] priCustomerSet

    // This method is called from Activating and fill the
    // list with all records from the customers table
    Procedure DoFillList
        Boolean bEofCustomer
        RowId[] riCustomerSet // Array of RowId's to keep track of the RowId per item
        Integer iItem

        Open Customer // Could be different based on your connection to Northwind

        Clear Customer
        Repeat
            Find Gt Customer By 5 // Find records sorted by Region
            Move (Finderr) To bEofCustomer
            If (Not (bEofCustomer)) Begin
                // Add the customer to the list
                Send Add_Item Msg_None Customer.Companyname
                // Get the amount of items currently
                Get Item_Count To iItem
                // Decrement by one because of 0 based array and list of items
                Decrement iItem
                // Get the RowId of the current record and store it in the N-th
                // value of RowId array
                Move (GetRowId (Customer.File_number)) To riCustomerSet[iItem]
                // Make the Aux_Value equal to the item
                Set Aux_Value Item iItem To iItem
            End
        Until (bEofCustomer)

        // Copy the contents of the RowId's array variable to the property
        Set priCustomerSet To riCustomerSet
    End_Procedure // DoFillList

    // Will be called only once when the object was not active yet
    Procedure Activating
        Forward Send Activating

        // Erase all existing information
        Send Delete_Data
        // Find the records and add them to the list
        Send DoFillList
        // Make the current item display in the forms
        Send OnChange
    End_Procedure // Activating

    Procedure OnChange
        Integer iCurrentItem iRowIdItem
        RowId[] riCustomerSet // Variable to hold the contents of the RowId's property
        Boolean bCustomerFound

        // Get the current list item        
        Get Current_Item To iCurrentItem
        // Retrieve the item number for the RowId array. The iCurrentItem will be
        // different from the Aux_Value when the list gets resorted. Click on the
        // sort names descending button
        Get Aux_Value Item iCurrentItem To iRowIdItem
        // Get the property with RowId's to the local variable
        Get priCustomerSet To riCustomerSet
        // Refind the record based on the value from the array variable
        Move (FindByRowId (Customer.File_number, riCustomerSet[iRowIdItem])) To bCustomerFound
        If (bCustomerFound) Begin
            // Display the CompanyName and ContactName
            Set Value Of oCompanyNameForm To Customer.Companyname
            Set Value Of oContactNameForm To Customer.Contactname
        End
        Else Begin
            // Erase all the data from the forms
            Send Delete_Data Of oCompanyNameForm
            Send Delete_Data Of oContactNameForm
        End
    End_Procedure // OnChange
End_Object    // oCustomerList