Handle Keyboard Events

There are new 3 events available.

  • BeforeCellKeyDown
  • AfterCellKeyDown
  • CellKeyUp

The BeforeCellKeyDown has the property IsCancelled that can be used to abort the built-in operations if it set to true.

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

protected override void OnLoad(EventArgs e)
  sheet.BeforeCellKeyDown += sheet_BeforeCellKeyDown;

void sheet_BeforeCellKeyDown(object sender, BeforeCellKeyDownEventArgs e)
  e.IsCancelled = (e.KeyCode == Keys.Enter);

Catching Cell Keyboard Events

Cell Key Up

This event raised when user released any key on worksheet inside any cells, for example:

void InitWorksheet()
  var sheet = gridControl.CurrentWorksheet;
  sheet.CellKeyUp += sheet_CellKeyUp;

Event body seems like below:

void sheet_CellKeyUp(object sender, CellKeyDownEventArgs e)
  MessageBox.Show("Pressed key is: " + e.KeyCode);


This event will not be raised when some key pressed inside worksheet that causes worksheet into Edit-mode, usually the char keys like A-Z, 0-9 and symbols will cause cell enter Edit-mode. Therefore if cells could be editable, sometimes only the BeforeCellKeyDown and AfterCellKeyDown could be handled.

Cell Editing Events

AfterCellEdit Event

This event is raised after user finished edit a cell.

See also cell edit.


Format cell data from 'text' to 'text' in AfterCellEdit:

var worksheet = reoGridControl.Worksheets[0];

worksheet.AfterCellEdit += Worksheet_AfterCellEdit;

void Worksheet_AfterCellEdit(object sender, CellAfterEditEventArgs e)
  e.NewData = "[" + e.NewData + "]";

Start to edit cell: 151

Press enter: 152

The text has been formatted.

Was the content of the page helpful?