ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Standard Keystroke Events

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

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:

·      Visual Basic

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

·      C#

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 ;

    }

}

·      Delphi

procedure TWinForm.C1TrueDBGrid1_KeyPress(sender: System.Object; e: System.Windows.Forms.KeyPressEventArgs);

begin

  // 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;

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


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.