Table of Contents

Keyboard & mouse

Configure how the user navigates and selects cells: arrow keys, Tab, Enter, Home/End, Insert/Delete, mouse drag, resize, touch — and control the built-in find/replace and cell-merge shortcuts.

Overview

All keyboard and mouse behaviour is concentrated under Grid.Options.Keyboard, Grid.Options.Mouse, Grid.Options.Selection, and Grid.Options.Lookup. The defaults match the conventions of Excel and most native grid controls, but every individual behaviour can be overridden.

Quick example

procedure TForm1.FormCreate(Sender: TObject);
begin
  // Direct edit: typing a character starts editing immediately
  Grid.Options.Keyboard.TabKeyDirectEdit   := True;
  Grid.Options.Keyboard.ArrowKeyDirectEdit := True;
  Grid.Options.Keyboard.EnterKeyDirectEdit := True;

  // What does Enter do? Move down (default), move right, or stay put.
  Grid.Options.Keyboard.EnterKeyMove := gkmMoveDown;

  // Selection style
  Grid.Options.Selection.Mode := gsmCellRange;       // contiguous range
  // Other modes: gsmSingleCell, gsmRow, gsmDisjunctRow, gsmDisjunctCellRange
end;

Keyboard options

Grid.Options.Keyboard:

Option Default Effect
EnterKeyHandling gekhNone Where Enter moves: gekhNone (stays), gekhNextRow, gekhNextColumn, gekhNextColumnInRow, gekhNextRowInColumn.
TabKeyHandling gtkhMixed Tab behaviour: gtkhNextControl (leaves grid), gtkhNextCell (stays in grid), gtkhMixed (wraps to next row, then leaves).
TabKeyDirection gtkdNextColumnCell Direction Tab moves: gtkdNextColumnCell (right) or gtkdNextRowCell (down).
HomeKeyHandling ghkhFirstColumn What Home does: ghkhNone, ghkhFirstRow, ghkhFirstColumn.
EndKeyHandling genkhLastColumn What End does: genkhNone, genkhLastRow, genkhLastColumn.
PageScrollSize 0 Rows per PgUp/PgDn (0 = one page of visible rows).

Direct edit

Option Default Effect
TabKeyDirectEdit False Tab also opens the inplace editor on the destination cell.
ArrowKeyDirectEdit False Arrow keys open the editor as they navigate.
EnterKeyDirectEdit False Enter both moves and starts editing.

Insert and delete

Option Default Effect
InsertKeyHandling gikhNone What Ins does: gikhNone, gikhInsertRowBefore, gikhInsertRowAfter.
DeleteKeyHandling gdkhNone What Del does: gdkhNone, gdkhDeleteRow, gdkhClearSelectedCells.

Auto-append

Option Default Effect
AppendRowOnArrowKeyDown False Pressing ↓ at the last row appends a new row.
AppendColumnOnArrowKeyRight False Pressing → at the last column appends a new column.

Built-in shortcuts

Option Default Effect
FindShortcut True Ctrl+F opens the built-in find dialog.
ReplaceShortcut True Ctrl+H opens the built-in replace dialog.
CellMergeShortcut False Enables a keyboard shortcut to merge the selected cell range.

Selection mode

Grid.Options.Selection.Mode:

Mode What it does
gsmSingleCell Exactly one cell selected at a time.
gsmCellRange A contiguous rectangular range.
gsmSingleRow One whole row at a time.
gsmDisjunctRow Multiple non-adjacent rows (Ctrl+Click).
gsmDisjunctCellRange Non-adjacent cells/ranges (Ctrl+Click).

ShowSelectionInFixedCells := True highlights the fixed header cell of the selected row or column.

Mouse options

Grid.Options.Mouse:

Sizing and dragging

Option Default Effect
ColumnSizing True Drag column borders to resize.
ColumnSizingMode gszmOneSided gszmOneSided resizes only the left column; gszmTwoSided redistributes width from both sides.
RowSizing True Drag row borders in the fixed column to resize rows.
RowSizingMode gszmOneSided Same two-sided option for rows.
FixedColumnSizing True Allow the user to resize fixed columns.
FixedRowSizing True Allow the user to resize fixed rows.
ColumnAutoSizeOnDblClick False Double-clicking a column border auto-sizes the column.
RowAutoSizeOnDblClick False Double-clicking a row border auto-sizes the row.
ColumnDragging True Drag column headers to reorder.
ColumnDragMode Configure whether dragging reorders columns or groups them visually.
RowDragging False Drag whole rows by their fixed cell to reorder.
DragMode gdmReorder gdmReorder for internal reorder; gdmDrag for drag-and-drop to external controls.

Scrolling

Option Default Effect
WheelScrollSize 3 Rows scrolled per mouse wheel tick.
WheelScrollKeepSelection False Keep the current cell selected while wheel-scrolling.
AutoScrolling True Auto-scroll when dragging near grid edges.
AutoScrollingSpeed Pixels per auto-scroll tick.
AutoScrollingInterval Timer interval for auto-scroll ticks.
TouchScrolling True Enable touch/swipe scrolling.
TouchScrollingSensitivity Minimum swipe distance before scroll starts.

Direct edit and fixed cell selection

Option Default Effect
DirectEdit False A single click opens the inplace editor (instead of requiring F2 or double-click).
FixedCellSelection Whether clicking fixed cells selects their row/column.

Lookup (typeahead)

Grid.Options.Lookup:

Option Default Effect
Enabled True Typing characters performs a prefix search in the focused column.
Incremental True Each new character extends the search string instead of starting fresh.
CaseSensitive False Case-sensitive prefix matching.
ResetInterval Milliseconds of inactivity after which the search string resets.

For programmatic search, call Grid.Lookup, Grid.LookupInColumn, or Grid.LookupInColumnFromRow.

Common patterns

Excel-like Enter behaviour

Grid.Options.Keyboard.EnterKeyHandling  := gekhNextRow;
Grid.Options.Keyboard.EnterKeyDirectEdit := True;

"Form" navigation — Tab moves right, Enter moves down

Grid.Options.Keyboard.TabKeyHandling  := gtkhNextCell;
Grid.Options.Keyboard.TabKeyDirection := gtkdNextColumnCell;
Grid.Options.Keyboard.EnterKeyHandling := gekhNextRow;

Delete key clears selected cells

Grid.Options.Keyboard.DeleteKeyHandling := gdkhClearSelectedCells;

Single-row select for a "list" feel

Grid.Options.Selection.Mode := gsmSingleRow;
  • Grid.Options.Keyboard.*
  • Grid.Options.Mouse.*
  • Grid.Options.Selection.Mode, ShowSelectionInFixedCells
  • Grid.Options.Lookup.Enabled / Incremental / CaseSensitive / ResetInterval
  • Grid.Lookup(AText), LookupInColumn(AText, AColumn), LookupInColumnFromRow
  • OnBeforeLookup, OnAfterLookup
  • OnSelectCell, OnSelectingCell — react to selection changes.
  • OnUpdateCursor — change the mouse cursor over specific cells.

See also

  • Editing cells — direct-edit shortcuts pair with editor configuration.
  • Clipboard — Ctrl+C/X/V come from the keyboard layer.
  • Merging cellsCellMergeShortcut enables the keyboard merge.