Skip to main content
A newer version of this page is available. .

TcxCustomTreeList.OnCompare Event

Occurs when sorting records within the TreeList control.

Declaration

property OnCompare: TcxTreeListNodeCompareEvent read; write;

Remarks

This event occurs when sorting node values.

The ANode1 and ANode2 parameters identify the nodes that must be compared.

The ACompare parameter represents the comparison result that must be defined by a developer. A negative value assigned to the parameter indicates that ANode1 is considered to be “less” than ANode2. And vice versa, if the ACompare parameter is set to a positive value, ANode1 is considered to be “greater” than ANode2. Two nodes are considered to be “equal” when the ACompare parameter is set to 0.

By default, the ACompare parameter is set to 1, thus indicating that ANode1 is “greater” than ANode2.

Use the OnCompare event when you want to change the default comparison rules. For instance, you can group records with Null values and place them at the bottom of all records, then group other rows according to their values (the same year and month) and so on.

Note

If your OnCompare event handler implementation is not thread-safe, we recommend that you disable the use of multi-threaded algorithms for node sorting operations via the tree list’s OptionsData.MultiThreadedSorting property.

The following example demonstrates how to sort nodes by the selected column:

//...
procedure <Form>.<TreeList>Compare(Sender: TcxCustomTreeList; ANode1,
  ANode2: TcxTreeListNode; var ACompare: Integer);
var
  val_ind : Integer;
begin
  val_ind := TreeList.FocusedColumn.ItemIndex;
  ACompare := ANode2.Values[val_ind] - ANode1.Values[val_ind];
end;
See Also