Back to Devexpress

CustomColumnSortEventArgs Class

wpf-devexpress-dot-xpf-dot-grid-afb76ad5.md

latest3.2 KB
Original Source

CustomColumnSortEventArgs Class

Provides data for the GridControl.CustomColumnSort event.

Namespace : DevExpress.Xpf.Grid

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

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public class CustomColumnSortEventArgs :
    EventArgs
vb
Public Class CustomColumnSortEventArgs
    Inherits EventArgs

CustomColumnSortEventArgs is the data class for the following events:

Remarks

To learn more, see Sorting Modes and Custom Sorting.

Example

The following example demonstrates how to use custom rules to sort data in the GridControl:

View Example: How to Use Custom Rules to Sort Data

xaml
<dxg:GridControl x:Name="grid"
                 CustomColumnSort="OnCustomColumnSort">
    <dxg:GridControl.Columns>
        <dxg:GridColumn FieldName="Day" GroupIndex="0" SortMode="Custom"/>
        <dxg:GridColumn FieldName="Employee"/>
    </dxg:GridControl.Columns>
</dxg:GridControl>
csharp
void OnCustomColumnSort(object sender, CustomColumnSortEventArgs e) {
    if(e.Column.FieldName == "Day") {
        int dayIndex1 = GetDayIndex(e.Value1);
        int dayIndex2 = GetDayIndex(e.Value2);
        e.Result = dayIndex1.CompareTo(dayIndex2);
        e.Handled = true;
    }
}
int GetDayIndex(object day) {
    return (int)Enum.Parse(typeof(DayOfWeek), (string)day);
}
vb
Private Sub OnCustomColumnSort(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.CustomColumnSortEventArgs)
    If Equals(e.Column.FieldName, "Day") Then
        Dim dayIndex1 As Integer = Me.GetDayIndex(e.Value1)
        Dim dayIndex2 As Integer = Me.GetDayIndex(e.Value2)
        e.Result = dayIndex1.CompareTo(dayIndex2)
        e.Handled = True
    End If
End Sub

Private Function GetDayIndex(ByVal day As Object) As Integer
    Return CInt(System.[Enum].Parse(GetType(System.DayOfWeek), CStr(day)))
End Function

Inheritance

Object EventArgs CustomColumnSortEventArgs

See Also

CustomColumnSortEventArgs Members

DevExpress.Xpf.Grid Namespace