TreeList.Sort(TreeListNode, TreeListColumn, SortOrder, Boolean) Method
Sorts the specified node’s children against a column. Allows you to sort root nodes.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v24.2.dll
Declaration
public void Sort(
TreeListNode node,
TreeListColumn column,
SortOrder order,
bool recursive = false
)
Parameters
Name | Type | Description |
---|---|---|
node | TreeListNode | The node whose children need to be sorted. Null, to sort root nodes. |
column | TreeListColumn | The sort column. |
order | SortOrder | The sort order. |
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
recursive | Boolean | False | true, to sort nodes recursively; otherwise, false. |
Remarks
An end-user can sort data with a click on a column header. In code, you typically use the TreeListColumn.SortOrder property to sort Tree List data. Both of these approaches sort nodes recursively, starting from the root nodes.
You can use the TreeList.Sort and TreeListNode.Sort methods to forcibly invoke the node sorting procedure. These methods have the recursive parameter that specifies if nodes need to be processed recursively. If this parameter is false, only immediate children of the specified node parameter are sorted.
After you call any of the Sort methods, an end-user can override the specified node sort order with a click on a column header. Use the TreeListOptionsCustomization.AllowSort and/or TreeListOptionsColumn.AllowSort properties to prevent users from changing the sort order.
The following code disables node sorting by end-users and then sorts the focused node’s children.
treeList1.OptionsCustomization.AllowSort = false;
treeList1.FocusedNode.Sort(treeList1.Columns["Department"], SortOrder.Ascending, false);
Set the node parameter to null to sort root nodes.
The TreeList.Sort and TreeListNode.Sort methods have overloads with the IComparer parameter. These overloads allow you to implement custom sort logic.
You can also implement a custom sort algorithm with the TreeList.CustomColumnSort event.