Skip to main content

TcxTreeListNode.CustomSort(TcxTreeListCompareFunc,Boolean) Method

Custom sorts the node’s children.

Declaration

procedure CustomSort(ASortProc: TcxTreeListCompareFunc; ARecurse: Boolean = False);

Parameters

Name Type
ASortProc TcxTreeListCompareFunc
ARecurse Boolean

Remarks

The ASortProc parameter specifies the comparison routine. If nil is passed as this parameter, a default comparison routine is used. This routine uses the OnCompare event handler, if defined. If the OnCompare event handler is not defined, the default routine uses a simple case-sensitive comparison of node captions.

The AItem1 and AItem2 parameters in the comparison routine refer to two items being compared. The routine’s return value indicates their relative order, as described in the table below.

Return value > 0 AItem1 comes before AItem2
Return value is 0 AItem1 and AItem2 are equivalent
Return value < 0 AItem2 comes before AItem1

The optional ARecurse parameter specifies if sorting should recursively traverse the node tree and sort each sub-tree in turn.

The following code shows how to use the CustomSort procedure to sort nodes by the two last symbols of phone numbers provided by the cxDBTreeList1Phone column.

function MyCustomSort(AItem1, AItem2: TcxTreeListNode): Integer;
begin
  Result := AnsiCompareStr(AnsiRightStr(AItem1.Texts[cxDBTreeList1Phone.ItemIndex], 2), AnsiRightStr(AItem2.Texts[cxDBTreeList1Phone.ItemIndex], 2));
end;
procedure <Form>.Button1Click(Sender: TObject);
begin
  cxDBTreeList1.FocusedNode.CustomSort(MyCustomSort, True);
end;
See Also