【发布时间】: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