ComponentOne True DBGrid Pro 8
Standard keystroke events

True DBGrid supports the standard keystroke events common to many ActiveX controls:

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.

You can use these events to restrict and modify user input as you would for any other intrinsic or ActiveX control. For example, the following KeyPress event handler converts the user's keystrokes to upper case letters, and prevents the user from entering non-alphanumeric characters:

Example Title
Copy Code
Private Sub TDBGrid1_KeyPress(KeyAscii As Integer)

    ' Convert key to upper case.

    KeyAscii = Asc(UCase(Chr$(KeyAscii)))

 

    ' Don't disable the Esc or Backspace keys.

    If (KeyAscii = 27) Or (KeyAscii = 8) Then Exit Sub

 

    ' Cancel user key input if it is not a letter or a digit.

    If (KeyAscii < 65 Or KeyAscii > 90) _

        And (KeyAscii < 48 Or KeyAscii > 57) Then

        KeyAscii = 0

    End If

End Sub

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback