Skip to main content

TdxSpreadSheetTableView.SortByColumnValues(TRect,TdxSortOrder[],Integer[]) Method

Sorts the specified cell range against multiple columns.

Declaration

procedure SortByColumnValues(const AArea: TRect; const ASortOrders: array of TdxSortOrder; const AColumns: array of Integer); overload;

Parameters

Name Type
AArea TRect
ASortOrders TdxSortOrder
AColumns Integer

Remarks

Call either of the overloaded function variants to sort values in a

Call this procedure to sort the cell data against multiple columns within the range passed as the AArea parameter. The sort order for each column is specified as the ASortOrders array parameter.

By default, if the first column has several equal values, the corresponding rows are sorted in the order defined by the second element of the ASortOrders and so on. The AColumns array of column indexes allows you to customize this sorting sequence, for instance, by putting the C column as the first one to sort, the A column as the second and so on.

The following image demonstrates the Spreadsheet control with data on countries:

Suppose, you want to sort against the continent and country columns in descending and ascending order, respectively. The following code performs such a sort of the selected cell range. As the values in the C column relate to the data of the two previous columns, you must specify all three columns in the sort method. In this example, the selected area is used as the sorting range, thus it is necessary to select all three columns with data before the code execution.

var
  AArea: TRect;
const
  ASortOrder: array[1..3] of TdxSortOrder =
  (
    soDescending, soAscending, soAscending
  );
  AColumns: array[1..3] of Integer = (0, 1, 2);
//...
  AArea := dxSpreadSheet1.ActiveSheetAsTable.Selection.Area;
  dxSpreadSheet1.ActiveSheetAsTable.SortByColumnValues(AArea, ASortOrder, AColumns);

The result is displayed below.

Note

A SortByColumnValues procedure call has no effect if the CanSort function returns False.

See Also