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
| Event | Description |
|---|---|
CellMouseDown | Raised when a mouse button is pressed on a cell |
CellMouseUp | Raised when a mouse button is released on a cell |
CellMouseMove | Raised when the mouse moves over cells |
CellMouseEnter | Raised when the mouse pointer enters a cell |
CellMouseLeave | Raised when the mouse pointer leaves a cell |
All events use CellMouseEventArgs.
CellMouseEventArgs Properties
| Property | Type | Description |
|---|---|---|
Cell | Cell | The cell instance. May be null if no data or style has been set on the cell |
CellPosition | CellPosition | Zero-based position of the cell (always available) |
Buttons | MouseButtons | Which mouse buttons are pressed |
RelativePosition | Point | Mouse position relative to the cell |
AbsolutePosition | Point | Mouse position relative to the control |
Clicks | int | Number of clicks (for double-click detection) |
Delta | int | Mouse wheel delta (only used in wheel events) |
Capture | bool | Get or set whether to capture the mouse |
CursorStyle | CursorStyle | Get or set the cursor style |
IsCancelled | bool | Set to true to cancel default ReoGrid operations |
Worksheet | Worksheet | The worksheet instance |
Note: The
Cellproperty may benullif the cell has no data or style. Usesheet.CreateAndGetCell(e.CellPosition)to ensure you get a valid cell instance.
CursorStyle Enum
| Value | Description |
|---|---|
PlatformDefault | Default cursor |
Hand | Hand cursor |
Selection | Range selection cursor |
FullRowSelect | Full row selector |
FullColumnSelect | Full column selector |
EntireSheet | Entire sheet selector |
Move | Move object |
Copy | Copy object |
ChangeColumnWidth | Column width resize |
ChangeRowHeight | Row height resize |
ResizeHorizontal | Horizontal resize |
ResizeVertical | Vertical resize |
Busy | Busy/waiting |
Cross | Crosshair |
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}");
}
};
Related Topics
- Keyboard Events — Cell keyboard events
- Cell Editing — Edit mode events
- Selection — Selection events