【问题标题】:Datagridview cell value evaluation vb.netDatagridview 单元格值评估 vb.net
【发布时间】:2016-05-13 13:53:25
【问题描述】:

我正在尝试处理我的 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

【问题讨论】:

    标签: vb.net datagridview cell isnumeric


    【解决方案1】:

    你可以处理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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多