ReoGrid provides three keyboard events on the worksheet for handling key presses inside cells.

Namespace

using unvell.ReoGrid;
using unvell.ReoGrid.Events;
using unvell.ReoGrid.Interaction;

Events

EventEventArgsDescription
BeforeCellKeyDownBeforeCellKeyDownEventArgsRaised before built-in key handling. Set IsCancelled = true to suppress default behavior
AfterCellKeyDownAfterCellKeyDownEventArgsRaised after built-in key handling
CellKeyUpCellKeyDownEventArgsRaised when a key is released

EventArgs Properties

CellKeyDownEventArgs

Base class for all keyboard event arguments.

PropertyTypeDescription
KeyCodeKeyCodeThe key that was pressed (includes modifier flags)
CellCellThe cell where the key event occurred
CellPositionCellPositionPosition of the cell

BeforeCellKeyDownEventArgs

Extends CellKeyDownEventArgs.

PropertyTypeDescription
IsCancelledboolSet to true to cancel the default operation

KeyCode Enum

The KeyCode enum (flags) represents keyboard keys. Common values:

ValueDescription
NoneNo key
BackBackspace
TabTab
EnterEnter
EscapeEscape
SpaceSpacebar
PageUpPage Up
PageDownPage Down
EndEnd
HomeHome
Left, Up, Right, DownArrow keys
InsertInsert
DeleteDelete
D0D9Number keys 0–9
AZLetter keys
NumPad0NumPad9Numpad keys
F1F24Function keys

Modifier Flags

ValueDescription
ShiftShift modifier (65536)
ControlCtrl modifier (131072)
AltAlt modifier (262144)
ModifiersBitmask to extract modifiers

Check for modifiers using bitwise AND:

if ((e.KeyCode & KeyCode.Control) == KeyCode.Control)
{
    // Ctrl is held
}

Examples

Cancel Default Key Behavior

Prevent Enter from moving the selection:

sheet.BeforeCellKeyDown += (s, e) =>
{
    if (e.KeyCode == KeyCode.Enter)
    {
        e.IsCancelled = true;
    }
};

Detect Key Combinations

sheet.BeforeCellKeyDown += (s, e) =>
{
    if (e.KeyCode == (KeyCode.Control | KeyCode.S))
    {
        // Ctrl+S pressed
        SaveWorkbook();
        e.IsCancelled = true;
    }
};

Handle Key Release

sheet.CellKeyUp += (s, e) =>
{
    Console.WriteLine($"Key released: {e.KeyCode} at cell {e.CellPosition}");
};

Handle After Key Down

sheet.AfterCellKeyDown += (s, e) =>
{
    if (e.KeyCode == KeyCode.Delete)
    {
        Console.WriteLine($"Cell {e.CellPosition} content cleared");
    }
};

Remarks

Keyboard events are not raised when a key press causes the cell to enter edit mode. Character keys (A–Z, 0–9, symbols) typically trigger edit mode on editable cells. In that case, only BeforeCellKeyDown fires (before edit mode starts). Use Cell Editing events to handle input during editing.

Was this article helpful?