[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Grids' (#lcl)

# TCustomGrid.KeyDown

Handles key down events for the grid control.

## Declaration

Source position: grids.pas line 1144

`protected procedure TCustomGrid.KeyDown(`
`var Key: Word;`
`Shift: TShiftState`
`); override;`

## Arguments

`Key` |  | Key code examined in the method.
`Shift` |  | Shift / Ctrl / Alt modifier for the key code.

## Description

KeyDown is overridden in TCustomGrid to ensure that keys handled by the grid or its Editor are properly applied to the control. KeyDown calls the inherited method on entry to signal the OnKeyDown event handler (when assigned) or any other key handlers for the control.

CanGridAcceptKey is called to determine whether Key and Shift are ignored in the control.

KeyDown handles the following key codes:

VK_TAB
  Performs cell navigation when goTabs in included in the Options for the grid. Ensures that goAutoAddRowsSkipContentCheck in Options is supported. When TabAdvance is set to aaNone, the key and modifier are forwarded to the Editor control.
VK_LEFT
  Moves to the previous cell when the Editor is not active.
VK_RIGHT
  Moves to the next cell when the Editor is not active.
VK_UP
  Moves the selection to the previous visible row.
VK_DOWN
  Moves the selection to the next visible row.
VK_PRIOR (Page Up)
  Moves upward in the grid by the number of visible rows.
VK_NEXT (Page Down)
  Moves downward in the grid by the number of visible rows.
VK_HOME
  Moves to the first non-fixed row in the grid. The current column is used. When goRelaxedRowSelect is included in Options, the selection is moved to the first non-fixed column in the current row.
VK_END
  Moves to the last non-fixed row in the grid. The current column is used. When goRelaxedRowSelect is included in Options, the selection is moved to the last non-fixed column in the current row.
VK_APPS (Menu Pop-up on PC keyboards)
  Displays the Pop-up menu for the cell Editor when editing is allowed in the column.
VK_F2
  Selects and displays the cell Editor when editing is allowed in the column.
VK_BACK (Backspace)
  Forwards the Backspace character (^H) to the cell Editor when editing is allowed in the column.
VK_C
  Performs a copy to clipboard operation when ssCtrl or ssMeta is in the Shift modifier.
VK_V
  Performs a paste from clipboard operation when ssCtrl or ssMeta is in the Shift modifier.
VK_X
  Performs a cut to clipboard operation when ssShift is in the Shift modifier.
VK_DELETE
  Clears the value in the cell Editor and redraws the current cell when editing is allowed for the column.
VK_ESCAPE
  Resets the value in the cell Editor, and hides the Editor control when it is both assigned and visible.

When Key is handled in the method, it is set to 0 (zero).

Called from EditorKeyDown when key down events are enabled in the EditorOptions for the control.

## See also

TWinControl.KeyDown |  | Signals OnKeyDown event handlers (when assigned).