ReoGrid provides five mouse events on the worksheet for handling mouse interactions with cells.

Namespace

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

Events

EventDescription
CellMouseDownRaised when a mouse button is pressed on a cell
CellMouseUpRaised when a mouse button is released on a cell
CellMouseMoveRaised when the mouse moves over cells
CellMouseEnterRaised when the mouse pointer enters a cell
CellMouseLeaveRaised when the mouse pointer leaves a cell

All events use CellMouseEventArgs.

CellMouseEventArgs Properties

PropertyTypeDescription
CellCellThe cell instance. May be null if no data or style has been set on the cell
CellPositionCellPositionZero-based position of the cell (always available)
ButtonsMouseButtonsWhich mouse buttons are pressed
RelativePositionPointMouse position relative to the cell
AbsolutePositionPointMouse position relative to the control
ClicksintNumber of clicks (for double-click detection)
DeltaintMouse wheel delta (only used in wheel events)
CaptureboolGet or set whether to capture the mouse
CursorStyleCursorStyleGet or set the cursor style
IsCancelledboolSet to true to cancel default ReoGrid operations
WorksheetWorksheetThe worksheet instance

Note: The Cell property may be null if the cell has no data or style. Use sheet.CreateAndGetCell(e.CellPosition) to ensure you get a valid cell instance.

CursorStyle Enum

ValueDescription
PlatformDefaultDefault cursor
HandHand cursor
SelectionRange selection cursor
FullRowSelectFull row selector
FullColumnSelectFull column selector
EntireSheetEntire sheet selector
MoveMove object
CopyCopy object
ChangeColumnWidthColumn width resize
ChangeRowHeightRow height resize
ResizeHorizontalHorizontal resize
ResizeVerticalVertical resize
BusyBusy/waiting
CrossCrosshair

Examples

Cell Mouse Down

sheet.CellMouseDown += (s, e) =>
{
    // Safe: always use CellPosition, not Cell (which may be null)
    var cell = sheet.CreateAndGetCell(e.CellPosition);
    Console.WriteLine($"Clicked cell {e.CellPosition}: {cell.Data}");
};

Cell Mouse Up

sheet.CellMouseUp += (s, e) =>
{
    Console.WriteLine($"Mouse released at {e.CellPosition}, button: {e.Buttons}");
};

Cell Mouse Enter / Leave

sheet.CellMouseEnter += (s, e) =>
{
    // Highlight on hover
    if (e.Cell != null)
    {
        e.Cell.Style.BackColor = SolidColor.LightYellow;
    }
};

sheet.CellMouseLeave += (s, e) =>
{
    if (e.Cell != null)
    {
        sheet.RemoveRangeStyles(e.CellPosition, PlainStyleFlag.BackColor);
    }
};

Cancel Default Behavior

sheet.CellMouseDown += (s, e) =>
{
    if (e.CellPosition.Col == 0)
    {
        // Prevent selection on first column
        e.IsCancelled = true;
    }
};

Change Cursor Style

sheet.CellMouseMove += (s, e) =>
{
    if (e.Cell?.Data != null)
    {
        e.CursorStyle = CursorStyle.Hand;
    }
};

Detect Double Click

sheet.CellMouseDown += (s, e) =>
{
    if (e.Clicks == 2)
    {
        Console.WriteLine($"Double-clicked on {e.CellPosition}");
    }
};
Was this article helpful?