VB.Net中DataGridView控件列按数字排序的解决方法

Private Sub dgvResult_SortCompare(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewSortCompareEventArgs) Handles dgvResult.SortCompare
        If e.Column.Index > 0 Then
            If dgvResult.Columns.Item(e.Column.Index).HeaderText.IndexOf("N") > 0 Then
                If (Val(e.CellValue1) < Val(e.CellValue2)) Then
                    e.SortResult = -1
                ElseIf Val(e.CellValue1) = Val(e.CellValue2) Then
                    e.SortResult = 0
                Else
                    e.SortResult = 1
                End If
                e.Handled = True
            End If
        End If

    End Sub

你可能感兴趣的:(datagridview)