Skip to main content

How to Implement Sorting

  • 2 minutes to read

The ExpressQuantumTreeList provides easy data sorting at runtime. The TreeList control represents data in columns, each of which has a caption displayed in the column header panel. End users can click a column’s header to sort data by the column’s values. Sorting applies to nodes located at the same level and having the same parent node.

A column whose values are used to sort nodes displays a small arrow in its caption to indicate the current sort order. End users can hold down the Ctrl key and click the header again to clear sorting. To prohibit end users from sorting data, set the TreeList control’s OptionsBehavior.Sorting property or a column’s Options.Sorting property to False.

End users can hold down the Shift key and click column headers to sort data by multiple columns. In this instance, sorting orders the data according to the first column specified for sorting. Other column values only come into play if the previous column’s data is identical. Use the TreeList control’s SortedColumnCount and SortedColumns properties to find out the order of sorted columns.

The following image shows the TreeList control with data sorted in ascending order by the Budget column and in descending order by Location.

You can implement this as follows:

// lock updates
cxTreeList1.BeginUpdate;
try
// clear sorting
  cxTreeList1.ClearSorting;
// sort the budget column in ascending order
  tlcolBudget.SortOrder := soAscending;
// sort the location column in descending order
  tlcolLocation.SortOrder := soDescending;
finally
// unlock updates and apply the changes
  cxTreeList1.EndUpdate;
end;
See Also