V4 V5

The control comes with Excel-like key and mouse behaviour out of the box. There is no wiring to write.

Keyboard

Moving and selecting

KeyWhat it does
← ↑ → ↓Moves the active cell by one
Shift + arrowExtends the selection
Tab / Shift+TabRight / left
Enter / Shift+EnterDown / up
HomeTo the start of the row (column A)
Ctrl + HomeTo A1
PageDown / PageUpOne screen down / up
Shift + PageDown / PageUpExtends the selection by one screen

Editing

KeyWhat it does
F2Starts editing the cell
Any characterReplaces the content with it and starts editing
Delete / BackspaceClears the active cell
EscCancels the edit
EnterCommits and moves down

Formatting, history and clipboard

KeyWhat it does
Ctrl + B / I / UBold / italic / underline (the selected characters while editing, the selected cells otherwise)
Ctrl + C / X / VCopy / cut / paste
Ctrl + ZUndo
Ctrl + Shift + Z / Ctrl + YRedo

Ctrl+B and friends change target depending on whether you are editing: while editing a cell they apply to the selected characters, otherwise to the whole selection (Rich Text).

Mouse

ActionWhat it does
ClickSelects a cell
DragSelects a range
Double-clickStarts editing the cell
Click a row or column headerSelects the whole row or column
Click the top-left cornerSelects the whole sheet
Drag a header boundaryChanges a row height or column width
Double-click a header boundaryAuto-fits it to the content
Drag the handle at the selection’s bottom-rightAuto-fill
WheelScrolls vertically
Ctrl + wheelChanges the zoom in 10% steps
Right-clickRaises ContextMenuRequested
Click the on a headerOpens the auto-filter panel
+ / in the outline panelExpands or collapses a group

With several rows (or columns) selected, dragging a boundary inside the selection resizes all of them at once.

Resizing and auto-fill are recorded in the history, so Ctrl+Z reverses them (Undo and Redo).

Japanese input

Starting Japanese input on a cell that is not being edited opens the editor in place and continues the composition there. The candidate window appears at the active cell.

This is the same on all three of WinForms, WPF and Avalonia. The Avalonia build works the same way on Linux and macOS through each OS’s own input method.

Intercepting on the host side

There is no API for remapping keys. To change them, derive from the control and handle the key event first.

WinForms:

public class MyGrid : ReoGridControl
{
    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.Control && e.KeyCode == Keys.S) { Save(); e.Handled = true; return; }
        base.OnKeyDown(e);   // fall through to the defaults
    }
}

WPF and Avalonia use the same shape (overriding OnKeyDown).

Setting e.Handled = true and not calling base prevents the default behaviour. To add something after the default, call base first.

Application-wide shortcuts (Ctrl+S and the like) sit more naturally on the window than on the grid. The grid does not swallow keys it has no use for, so window menu accelerators keep working.

Preventing editing

For a read-only view, close the three doors that start an edit: F2 and Delete, typing a character, and double-clicking a cell.

public class ReadOnlyGrid : ReoGridControl
{
    protected override void OnKeyDown(KeyEventArgs e)
    {
        if (e.KeyCode is Keys.F2 or Keys.Delete or Keys.Back) { e.Handled = true; return; }
        base.OnKeyDown(e);           // movement and copying still work
    }

    // stop a character keystroke from starting an edit
    protected override void OnKeyPress(KeyPressEventArgs e) { e.Handled = true; }

    // stop a double-click from starting one (do not call base)
    protected override void OnMouseDoubleClick(MouseEventArgs e) { }
}

To block pasting (Ctrl+V) as well, add Keys.V when e.Control to the condition above.

If the goal is simply to forbid input, sheet protection is more reliable than swallowing keys. Call ws.Protect() to protect the sheet and ws.SetRangeLock(range, LockState.Unlocked) to open just the ranges that stay editable; refusals are reported through ws.EditRefused.

Was this article helpful?