【问题标题】:DataGridView sorting with nulls in Decimal columnDataGridView 在 Decimal 列中使用空值进行排序
【发布时间】:2014-06-12 12:17:16
【问题描述】:

问题是null值大于十进制值0.00,所以出现升序排序问题。

Private Sub dgvTable_SortCompare(ByVal sender As Object, ByVal e As DataGridViewSortCompareEventArgs) Handles dgvTable.SortCompare
    If e.Column.Index = 4 Then
        e.SortResult = System.Decimal.Compare(todecimalnull(e.CellValue1), todecimalnull(e.CellValue2))
    End If

    e.Handled = True
End Sub

Function todecimalnull(ByVal cellvalue)
    If cellvalue = "" Then
        Return "0.0"
    Else
        Return cellvalue
    End If
End Function

【问题讨论】:

  • 我想用上面的代码先为null,然后是0.0000,请尽快帮助我

标签: vb.net datagridview


【解决方案1】:

我建议使用 0 而不是 null 填充数据网格视图。 将 value 保留为 null 可能是有原因的,但这些可能比排序问题更重要。

这是一个关于首先使用非空值进行排序的不错的 SO 线程。

How to order by column with non-null values first in sql

可能需要自定义排序 - 而不是单击列,或重载排序列以应用此逻辑。 (这可能吗?)

【讨论】:

    猜你喜欢
    • 2010-10-26
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2016-12-05
    相关资源
    最近更新 更多