20-12-12, 10:51 PM
كود :
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing Dim TextEdit As TextBox = e.Control
RemoveHandler TextEdit.KeyPress, AddressOf TextBox_KeyPress_Number
AddHandler TextEdit.KeyPress, AddressOf TextBox_KeyPress_Number
End Sub
Public Sub TextBox_KeyPress_Number(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
Dim KeyAscii As Short = Asc(e.KeyChar)
Select Case KeyAscii
Case 48, 49, 8
e.Handled = False
Case Else
e.Handled = True
End Select
' 48 is KeyAscii for Number 0
' 49 is KeyAscii for Number 1
' 8 is KeyAscii for Back Key
End Sub
