0
我想處理我的datagridview單元格數據(的特定列)來評估用戶輸入首先爲一個數值然後爲值介於0和90 ...此代碼幾乎工作相同的文本框的情況,但當我嘗試並將其應用於datagridview單元格的情況一切都會錯過..我該如何解決這個問題?datagridview單元格值評估vb.net
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
由於多數民衆贊成在正確的方向讓我:) – TM80
愉快:) –