code below is not working correctly. The key_down event only fires on control keys. I thought it would fire on any key pressed. The key press event is not firing after the key down event. I''m trying to stop a user from entering in alpha keys. thanks
Private Sub dsEditData_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dsEditData.KeyDown
'' Initialize the flag to false.
nonNumberEntered = False
'' Determine whether the keystroke is a number from the top of the keyboard.
If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
'' Determine whether the keystroke is a number from the keypad.
If e.KeyCode < Keys.NumPad0 OrElse e.KeyCode > Keys.NumPad9 Then
'' Determine whether the keystroke is a backspace.
If e.KeyCode <> Keys.Back Then
'' A non-numerical keystroke was pressed.
'' Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = True
End If
End If
End If
End Sub
Private Sub dsEditData_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles dsEditData.KeyPress
Dim cc As GridCurrentCell = Me.dsEditData.CurrentCell
Dim newValue As String = Me.dsEditData(cc.RowIndex, cc.ColIndex).FormattedText
Dim dr As DataRow = dsData.Tables("DataPointDetail").Rows(cc.RowIndex - 1)
If nonNumberEntered = True Then
'' Stop the character from being entered into the control since it is non-numerical.
e.Handled = True
Else
UpdateData(cc.ColIndex, dr, newValue)
End If
End Sub