Skip to main content
A newer version of this page is available. .
All docs
V20.2

TreeViewControl.CustomNodeSort Event

Allows you to use custom rules to sort data.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.2.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core

Declaration

public event TreeViewCustomNodeSortEventHandler CustomNodeSort

Event Data

The CustomNodeSort event's data class is DevExpress.Xpf.Grid.TreeList.TreeViewCustomNodeSortEventArgs.

Remarks

Set the SortMode property to Custom and handle the CustomNodeSort event to apply custom logic to sort data.

When you handle this event, you need to compare two nodes. The Value1 and Value2 parameters identify the values of these nodes. Set the result of the comparison to the Result parameter as follows:

  • -1 to position the first row above the second row when data is sorted in ascending order. When data is sorted in descending order, the TreeViewControl positions the first row below the second row.
  • 1 to position the first row below the second row when data is sorted in ascending order. When data is sorted in descending order, the TreeViewControl positions the first row above the second row.
  • 0 to indicate that the rows are equal. In this case, the TreeViewControl arranges rows according to their indices in a data source.

Set the Handled parameter to true to use the custom comparison. Leave this parameter set to false to invoke the default comparison mechanism after your event handler has finished. In this instance, the TreeViewControl ignores the custom comparison’s result.

Example

<dxg:TreeViewControl SortMode="Custom" 
                     CustomNodeSort="treeview_CustomNodeSort"
                     SortOrder="Ascending"
                     ...>
void treeview_CustomNodeSort(object sender, DevExpress.Xpf.Grid.TreeList.TreeViewCustomNodeSortEventArgs e) {
    int dayIndex1 = GetDayIndex((string)e.Value1);
    int dayIndex2 = GetDayIndex((string)e.Value2);
    e.Result = dayIndex1.CompareTo(dayIndex2);
    e.Handled = true;
}
See Also