We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Currentcellkeypress event is not firing

Thread ID:





10272 Jan 28,2004 12:23 PM UTC Jan 28,2004 02:11 PM UTC WinForms 1
Tags: GridControl
Patrick Rumery
Asked On January 28, 2004 12:23 PM UTC

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

Administrator [Syncfusion]
Replied On January 28, 2004 02:11 PM UTC

CurrentCellKeyPress is the event you should use to get every keystroke in a cell. It catches both the first keystroke on an inactive cell as well as subsequent keystrokes into the active cell (when the grid no longer has input focus.) But there is a special event you can handle to validate cell contents on a keystroke by keystroke basis. It is CurrentCellValidateString. It gives you easy access to the potential new string so you can easily validate things. Here is code that will only allow the user to type a valid double. Private Sub GridControl1_CurrentCellValidateString(ByVal sender As Object, ByVal e As GridCurrentCellValidateStringEventArgs) Handles GridControl1.CurrentCellValidateString Dim cc As GridCurrentCell = Me.GridControl1.CurrentCell ''check only column 1 for example.... If cc.ColIndex <> 1 Then Return End If Try If e.Text <> "." Then Dim d As Double = Double.Parse(e.Text) End If Catch e.Cancel = True Return End Try End Sub


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon