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

TreeList.CustomColumnSort Event

Allows you to apply custom sorting for those Tree List columns whose TreeListColumn.SortMode is set to Custom.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v19.1.dll

Declaration

[DXCategory("Behavior")]
public event CustomColumnSortEventHandler CustomColumnSort

Event Data

The CustomColumnSort event's data class is DevExpress.XtraTreeList.CustomColumnSortEventArgs.

Example

The code below implements a custom sorting algorithm for a Tree List column via the TreeList.CustomColumnSort event. The sorting procedure arranges nodes that have children above the nodes that do not have children.

The images below display the control sorted by the Department column in ascending and descending order. Notice that the Finance node is always located under nodes that have children.

Sorting - Custom

using DevExpress.XtraTreeList;

treeList1.Columns["Department"].SortMode = DevExpress.XtraGrid.ColumnSortMode.Custom;

private void TreeList1_CustomColumnSort(object sender, DevExpress.XtraTreeList.CustomColumnSortEventArgs e) {
    if (e.Node1.HasChildren && !e.Node2.HasChildren)
        e.Result = e.SortOrder == SortOrder.Ascending ? -1 : 1;
    if (!e.Node1.HasChildren && e.Node2.HasChildren)
        e.Result = e.SortOrder == SortOrder.Ascending ? 1 : -1;

}
See Also