ComponentOne True DBGrid for WinForms
Cell Editing Techniques / Handling Editing Events / Standard Keystroke Events
In This Topic
    Standard Keystroke Events
    In This Topic

    True DBGrid for WinForms supports the standard keystroke events contained in the .NET environment:

    Event Description
    KeyDown Fired when the user presses a key.
    KeyPress Fired when the user presses an ANSI key.
    KeyUp Fired when the user releases a key.

    The KeyDown and KeyUp events trap all keys, including function keys, ALT and SHIFT keys, and numeric keypad keys. The KeyPress event only traps letters and numbers, punctuation marks and symbols, and editing keys such as TAB, ENTER, and BACKSPACE.

    Use these events to restrict and modify user input as you would be done for any other intrinsic .NET control. For example, the following KeyDown event handler prevents the user from entering non-alphanumeric characters:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Private Sub C1TrueDBGrid1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles C1TrueDBGrid1.KeyPress
     
        ' Cancel user key input if it is not a letter or a digit.
        If Not e.KeyChar.IsLetterOrDigit(e.KeyChar) Then
            e.Handled = True
        End If
    End Sub
    

    To write code in C#

    C#
    Copy Code
    private void C1trueDBGrid1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
        // Cancel user key input if it is not a letter or a digit.
        if (! e.Keychar.IsLetterOrDigit(e.KeyChar])
        {
           e.Handled = true ;
        }
    }
    

    For more information on these or any other native .NET events see MSDN or .NET help.