All docs
V20.1
20.2 (EAP/Beta)
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

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.v20.1.dll

Declaration

public void Sort(
    TreeListNode node,
    TreeListColumn column,
    SortOrder order,
    bool recursive = false
)
Public Sub Sort(
    node As TreeListNode,
    column As TreeListColumn,
    order As SortOrder,
    recursive As Boolean = 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.

See Also