sortAsc

Type: Boolean (list box), Boolean array (table)

Availability: Read or write at run time only

The sortAsc property controls whether the sorting of a ListBox or Table control is ascending or descending. The sortAsc property defaults to true. If the sorted property of the list box is not set, the sortAsc property has no meaning.

Each sheet of a table control can have in the range zero through six sorted columns. The sorting sets these properties for the sheet, as required. Each sheet of a Table control has an array of six items (the entries are 1‑relative).

The column numbers can be established at any time, and are not validated when set. If the column is invalid, it is ignored when sorted. If a sort column is zero (0), the remaining sort column values are ignored. If no sort column is set, no sorting is performed.

When the text of a sorted column changes, the automatic sorting of rows occurs only when the Table class addItem method adds a new row or the Table class resort method is used.

As the number of rows can initially be set, the table control keeps a record of the highest row that has had text set. The sort involves only the rows up to and including that row.

Fixed rows of a Table control are not sorted.

The following examples show the use of the sortAsc property.

//  toggle sort on columns ...
instancesTable.sortColumn[1] := table.column;
instancesTable.sortAsc[1]    := not instancesTable.sortAsc[1];
instancesTable.resort;

table1_dblClick(table: Table input) updating;
begin
    if table.row = 1 then
        table1.sortColumn[1] := table.column;
        table1.sortAsc[1]    := true;
        table.resort;
    endif;
end;

The code fragment in the following example sorts the table based on three columns: 4, 1, and 7. Column 4 is sorted in ascending order, column 1 in descending order, column 7 in ascending order, and no columns are sorted by case; that is, they are case-insensitive.

table1.sortColumn[1] := 4;     // first sort column is 4
table1.sortAsc[1]    := true;
table1.sortCased[1]  := false;
table1.sortColumn[2] := 1;     // second sort column is 1
table1.sortAsc[2]    := false;
table1.sortCased[2]  := false;
table1.sortColumn[3] := 7;     // third sort column is 7
table1.sortAsc[3]    := true;
table1.sortCased[3]  := false;