Datagridview 单元格值评估 vb.net

Datagridview cell value evaluation vb.net

我正在尝试处理我的 datagridview 单元格数据(特定列的)以首先评估用户输入的数值,然后评估介于 0 和 90 之间的值...此代码对文本框的作用几乎相同情况,但是当我尝试将它应用于 datagridview 单元格情况时,一切都丢失了。我该如何解决这个问题?

    Private Sub DataGridView1_EditingControlShowing1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
    If DataGridView1.CurrentCell.ColumnIndex = 1 Then
        Dim txtedit As TextBox = DirectCast(e.Control, TextBox)
        AddHandler txtedit.KeyPress, AddressOf txtEdit_KeyPress
    End If
End Sub

    Private Sub txtEdit_KeyPress(ByVal sender As Object, ByVal e As KeyPressEventArgs)

    If IsNumeric(DataGridView1.CurrentCell.Value) Then 
        'VALIDATES CURRENT CELL INPUT TO VALUES RANGING BETWEEN 1 AND 90°...
        If DataGridView1.CurrentCell.Value <= 0 Or DataGridView1.CurrentCell.Value >= 91 Then
            MessageBox.Show("The angle you are trying to achieve is " & DataGridView1.CurrentCell.Value & "°." & vbCrLf & vbCrLf & "Only values ranging from 1° to 90° are permitted.", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
        Else
            'NOTHING
        End If
    Else
        MessageBox.Show("Only numeric values are permitted.", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
    End If
End Sub

你可以处理 DataGridView1_CellEndEdit:

   Private Sub DataGridView1_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit

        Try
            Dim order As DataGridView = DirectCast(sender, DataGridView)

            If IsNumeric(order("NmeOfColumn", e.RowIndex).Value) Then

                If order("NmeOfColumn", e.RowIndex).Value <= 0 Or order("NmeOfColumn", e.RowIndex).Value >= 91 Then
                    MessageBox.Show("The angle you are trying to achieve is " & DataGridView1.CurrentCell.Value & "°." & vbCrLf & vbCrLf & "Only values ranging from 1° to 90° are permitted.", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
                Else
                    'NOTHING
                End If
            Else
                MessageBox.Show("Only numeric values are permitted.", "Attention!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
            End If


        Catch ex As Exception

        End Try
    End Sub