【问题标题】:Implementing a custom column sorting实现自定义列排序
【发布时间】:2016-09-18 03:45:33
【问题描述】:

我在对数据网格列实施自定义排序时遇到问题。有人可以解释我做错了什么吗?

我正在尝试为列创建自定义排序,以便字符串首先按长度排序,然后按它们的值排序。它到达我的自定义函数,点击“Throws not implemented line”,然后给我一个 InvalidOperationException 错误。

Private Sub customSorting(sender As Object, e As DataGridSortingEventArgs) Handles grid.Sorting

    If e.Column.Header = "Test" Then
        Dim comp As IComparer = New RowComparer(e.Column.SortDirection)
        Dim lcv As ListCollectionView = CollectionViewSource.GetDefaultView(grid.ItemsSource)
        lcv.CustomSort = comp
        e.Handled = True
    End If
End Sub

Private Class RowComparer
    Implements System.Collections.IComparer
    Private o As Integer = 0 

    Public Sub New(order As Integer)
        o = order
    End Sub

    Public Function Compare(x As Object, y As Object) As Integer Implements IComparer.Compare
        Throw New NotImplementedException()
        If x.ToString.Length > y.ToString.Length Then
            If o = 0 Then
                Return 1
            Else
                Return -1
            End If
        ElseIf x.ToString.Length < y.ToString.Length Then
            If o = 0 Then
                Return -1
            Else
                Return 1
            End If
        Else
            Return String.Compare(x, y)
        End If
    End Function
End Class

【问题讨论】:

    标签: wpf vb.net xaml sorting datagrid


    【解决方案1】:

    Visual Studios 自动生成了“Throw New NotImplementedException()”,它正在停止我的程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      相关资源
      最近更新 更多