wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-3600ac8c.md
Allows you to use custom rules to sort data.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public event TreeViewCustomNodeSortEventHandler CustomNodeSort
Public Event CustomNodeSort As TreeViewCustomNodeSortEventHandler
The CustomNodeSort event's data class is DevExpress.Xpf.Grid.TreeList.TreeViewCustomNodeSortEventArgs.
Follow the steps below to apply custom logic to sort data:
Ascending or Descending.Custom.CustomNodeSort event.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:
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.
<dxg:TreeViewControl SortOrder="Ascending"
SortMode="Custom"
CustomNodeSort="treeview_CustomNodeSort"
...>
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;
}
int GetDayIndex(string day) {
return (int)Enum.Parse(typeof(DayOfWeek), day);
}
Private Sub treeview_CustomNodeSort(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.TreeList.TreeViewCustomNodeSortEventArgs)
Dim dayIndex1 As Integer = GetDayIndex(CStr(e.Value1))
Dim dayIndex2 As Integer = GetDayIndex(CStr(e.Value2))
e.Result = dayIndex1.CompareTo(dayIndex2)
e.Handled = True
End Sub
Private Function GetDayIndex(ByVal day As String) As Integer
Return CInt([Enum].Parse(GetType(DayOfWeek), day))
End Function
See Also