Cells enter edit mode when the user double-clicks or presses F2. ReoGrid overlays a text box on top of the cell to capture input.

Styled Spreadsheet

Namespace

using unvell.ReoGrid;

Start Editing

Use StartEdit on a worksheet to begin editing a cell. If another cell is already in edit mode, ReoGrid ends that session first.

// Edit the currently selected cell
sheet.StartEdit();

// Edit the selected cell with initial text
sheet.StartEdit("initial text");

// Edit by position
sheet.StartEdit(new CellPosition("A1"));
sheet.StartEdit(new CellPosition("A1"), "initial text");

// Edit by row and column index
sheet.StartEdit(2, 3);
sheet.StartEdit(2, 3, "initial text");

StartEdit Overloads

SignatureDescription
StartEdit()Edit the currently selected cell
StartEdit(string newText)Edit the selected cell with initial text displayed in the edit field
StartEdit(CellPosition pos)Edit cell at the specified position
StartEdit(CellPosition pos, string newText)Edit cell at the specified position with initial text
StartEdit(int row, int col)Edit cell at the specified row and column index
StartEdit(int row, int col, string newText)Edit cell at the specified row and column with initial text

All overloads return bool โ€” true if edit mode started successfully, false otherwise (e.g., cell is read-only or BeforeCellEdit was cancelled).

Start Edit from Cell Instance

var cell = sheet.Cells["A1"];
cell.StartEdit();

End Editing

Use EndEdit to finish an edit. The EndEditReason controls whether changes are committed or discarded.

// End editing normally (commit changes)
sheet.EndEdit();
sheet.EndEdit(EndEditReason.NormalFinish);

// Cancel editing (discard changes)
sheet.EndEdit(EndEditReason.Cancel);

// End editing with custom data (overrides user input)
sheet.EndEdit("Override Value");
sheet.EndEdit("Override Value", EndEditReason.NormalFinish);

EndEdit Overloads

SignatureDescription
EndEdit(EndEditReason reason = EndEditReason.NormalFinish)End editing with the specified reason
EndEdit(object data)End editing with custom data instead of user-entered text
EndEdit(object data, EndEditReason reason)End editing with custom data and specified reason

All overloads return bool โ€” true if the worksheet was in edit mode and the operation completed successfully.

End Edit from Cell Instance

var cell = sheet.Cells["A1"];
cell.EndEdit("new data");

EndEditReason Enum

ValueDescription
NormalFinishUser completed editing normally (Enter, Tab, click elsewhere). Changes are committed.
CancelUser cancelled the edit (Escape). Changes are discarded.

Edit State Properties

// Check if any cell is currently being edited
bool isEditing = sheet.IsEditing;

// Get the cell currently being edited (null if not editing)
Cell editingCell = sheet.EditingCell;

// Get or set the current text in the edit text box
string editText = sheet.CellEditText;
sheet.CellEditText = "modified text";
PropertyTypeDescription
IsEditingboolWhether any cell is currently in edit mode (read-only)
EditingCellCellThe cell currently being edited, or null (read-only)
CellEditTextstringThe current text in the edit text box (read/write)

Read-Only Cells

Prevent editing on individual cells:

var cell = sheet.Cells["A1"];
cell.IsReadOnly = true;

Make the entire worksheet read-only:

sheet.SetSettings(WorksheetSettings.Edit_Readonly, true);

See Protection & Locking for comprehensive protection options.

Input Behavior Settings

// Disable automatic data formatting after input
sheet.SetSettings(WorksheetSettings.Edit_AutoFormatCell, false);

// Disable the friendly percent helper (appends % during editing)
sheet.SetSettings(WorksheetSettings.Edit_FriendlyPercentInput, false);

// Disable auto-adjust row height when font size increases
sheet.SetSettings(WorksheetSettings.Edit_AutoAdjustRowHeight, false);

See Settings for all worksheet settings.

Events

ReoGrid raises events before, during, and after edit mode. You can cancel an edit, validate text, or transform user input.

150

BeforeCellEdit

Fires right before the edit box appears. Set IsCancelled = true to block editing.

sheet.BeforeCellEdit += (s, e) =>
{
    // Block editing for specific cells
    if (e.Cell.Column == 0)
        e.IsCancelled = true;

    // Change the initial text shown in the edit box
    e.EditText = "default value";
};

CellBeforeEditEventArgs Properties:

PropertyTypeDescription
CellCellThe cell about to be edited
IsCancelledboolSet to true to prevent editing
EditTextstringText to display in the edit field (modifiable)

CellEditTextChanging

Fires when the edit text changes (typing, paste, or IME input). Use this to replace or validate text during editing.

sheet.CellEditTextChanging += (s, e) =>
{
    // Replace specific input with predefined data
    if (e.Text.Equals("specific input"))
    {
        e.Text = "predefined data";
    }
};

CellEditTextChangingEventArgs Properties:

PropertyTypeDescription
CellCellThe cell being edited
TextstringThe current edit text (modifiable โ€” set to replace)

CellEditCharInputed

Fires per character input. Provides details about the character and cursor position.

sheet.CellEditCharInputed += (s, e) =>
{
    Console.WriteLine($"Char: {(char)e.InputChar}, Position: {e.CaretPositionInLine}");
};

Note: In WPF, character replacement is not supported in this event. Use CellEditTextChanging instead. CellEditCharInputEventArgs Properties:

PropertyTypeDescription
CellCellThe cell being edited
InputCharintThe input character code (modifiable)
CaretPositionInLineintCaret position within the current line (read-only)
LineIndexintLine index in the edit text (read-only)
InputTextstringThe full current edit text (read-only)

AfterCellEdit

Fires after the user finishes editing. You can modify the resulting data, change the format, or cancel the edit to revert.

sheet.AfterCellEdit += (s, e) =>
{
    // Override the data
    e.NewData = ProcessInput(e.NewData);

    // Change the data format for the new data
    e.DataFormat = CellDataFormatFlag.Number;

    // Or cancel to revert to the original value
    // e.EndReason = EndEditReason.Cancel;
};

CellAfterEditEventArgs Properties:

PropertyTypeDescription
CellCellThe cell that was edited
NewDataobjectThe new data value (modifiable โ€” set to override user input)
EndReasonEndEditReasonReason the edit ended (modifiable โ€” set to Cancel to revert)
DataFormatCellDataFormatFlagData format to apply to the new data (modifiable)

CellValidation

Fires after validation is performed on the editing text. Provides validation results and allows overriding the valid/invalid status.

sheet.CellValidation += (s, e) =>
{
    if (!e.IsValid)
    {
        Console.WriteLine($"Validation failed: {e.Failures.Count} failure(s)");
    }

    // Override the validation result
    e.IsValid = true;
};

CellValidationEventArgs Properties:

PropertyTypeDescription
CellCellThe cell being validated
FailuresIList<IValidationFailure>List of validation failures (null or empty means valid)
IsValidboolWhether the input is valid (modifiable โ€” set to override)

See Data Validation for setting up validation rules.

CellDataChanged

Fires when cell data actually changes โ€” both from user editing and programmatic updates (e.g., SetCellData, paste). This is the final hook for observing data changes.

sheet.CellDataChanged += (s, e) =>
{
    Console.WriteLine($"Cell {e.Cell.Address} changed to: {e.Cell.Data}");
};

Note: CellDataChanged does not fire when the user presses Escape to cancel editing. It fires for both interactive and programmatic data changes.

Common Patterns

Restrict Editing to a Range

var editableRange = new RangePosition(3, 1, 2, 3);

sheet.SetRangeBorders(editableRange, BorderPositions.Outside, RangeBorderStyle.BlackSolid);
sheet[2, 1] = "Edit only allowed in this range:";

sheet.BeforeCellEdit += (s, e) =>
    e.IsCancelled = !editableRange.Contains(e.Cell.Position);

41

Auto-Uppercase Input

sheet.CellEditTextChanging += (s, e) =>
{
    e.Text = e.Text.ToUpper();
};

Validate and Reject Invalid Input

sheet.AfterCellEdit += (s, e) =>
{
    if (e.Cell.Column == 2 && !int.TryParse(e.NewData?.ToString(), out _))
    {
        e.EndReason = EndEditReason.Cancel;  // Revert to original value
    }
};
Was this article helpful?