Skip to main content

Example: TreeList.Sorted, TreeList.SortedColumnCount, TreeList.SortedColumns, Column.SortOrder

The following sample changes the sort order of all the columns within the tree list control. The TreeList control’s Sorted property must be set to True or the method does nothing.

procedure InvertSorting;
var
  I: Integer;
  ASortDesc: Boolean;
begin
  if not cxTreeList.Sorted then Exit;
  cxTreeList.BeginUpdate;
  try
    for I := 0 to cxTreeList.SortedColumnCount - 1 do
    begin
      ASortDesc := cxTreeList.SortedColumns[I].SortOrder = soDescending;
// changing the sort order of the current column
      cxTreeList.SortedColumns[I].SortOrder := TcxDataSortOrder(Integer(not ASortDesc) + 1);
    end;
  finally
    cxTreeList.EndUpdate;
  end;
end;