Skip to content

KeyDown Event

Description

Occurs when a key is pressed on the keyboard and the GridControl has focus.

Syntax

Public Event KeyDown( _
    ByRef [KeyCode](#) As Integer, _
    ByVal [Shift](#) As Integer _
)

Parameters

  • KeyCode: ASCII code for the key that was pressed.
  • Shift: Specifies whether the Shift, Ctrl, or ALT keys were pressed.

Remarks

This can be used in conjunction with the FocusedRow property to perform actions on the currently focused GridRow and GridRecordItems when a key or key combination is pressed.

Any combination of the Shift, Alt, and Ctrl keys can be used. The table below shows the possible values for the Shift parameter:

Shift Parameter Value Bit Mask
Shift 1 001
Ctrl 2 010
Shift + Ctrl 3 011
Alt 4 100
Alt + Shift 5 101
Alt + Ctrl 6 110
Shift + Alt + Ctrl 7 111

The PreviewKeyDown event will occur immediately BEFORE the KeyDown event is fired to give you a chance to cancel or filter a key press if needed.

Example

KeyDown Event Sample (Visual Basic)

This sample illustrates how to use the KeyDown event to check/uncheck the checkbox of a GridRecordItem in the currently focused GridRow.

Private Sub wndGridControl_KeyDown(KeyCode As Integer, Shift As Integer)  
    On Error Resume Next  

    ' If the SpaceBar is pressed, then toggle the state of the checkbox in  
    ' the first record of the focused row  
    If (KeyCode = 32) Then  
        Dim Item As GridRecordItem  
        ' Returns a reference to the row that currently has focus  
        Set Item = wndGridControl.FocusedRow.Record(0)  
        Item.Checked = Not Item.Checked  
    End If  
End Sub

See Also


Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.