Selection state belongs to the view. A Worksheet knows nothing about it.

Reading and moving
| Member | What it is |
|---|---|
control.Selection | The selected range (RangePosition, read-only) |
control.ActiveCell | The active cell (CellPosition, read-only) |
control.MoveTo(row, col) | Moves the active cell and collapses the selection to it |
control.SelectionChanged | Raised when the selection changes |
Working with the viewport directly, it is viewport.Selection / viewport.ActiveCell /
viewport.SetActiveCell(r, c) / viewport.ExtendSelectionTo(r, c) /
viewport.SelectColumn(col).
using unvell.ReoGrid.Core;
using unvell.ReoGrid.Core.Rendering;
viewport.SetActiveCell(2, 1); // make B3 active (the selection collapses to B3)
viewport.ExtendSelectionTo(6, 2); // extend to B3:C7
RangePosition selection = viewport.Selection;
CellPosition active = viewport.ActiveCell;
viewport.SelectColumn(3); // the whole of column D
viewport.SelectRow(0); // the whole of row 1
viewport.SelectAll();
// whether whole rows or columns are selected is answerable without inspecting the range
bool wholeColumns = viewport.SelectionIsWholeColumns;
Bulk operations on the selection
The control has a full set of helpers that act on the selection. When whole rows or columns are selected they are routed to the row or column default style automatically, so nothing ever walks a million cells.
Formatting
| Member |
|---|
ToggleSelectionBold() / ToggleSelectionItalic() / ToggleSelectionUnderline() |
SetSelectionTextColor(color) / SetSelectionBackColor(color) |
SetSelectionFontFamily(family) / SetSelectionFontSize(size) |
SetSelectionHAlign(align) / SetSelectionVAlign(align) / SetSelectionWrap(wrap) |
SetSelectionNumberFormat(format) |
MutateSelectionStyle(s => s with { ... }) — any transformation |
Structure
| Member |
|---|
MergeSelection() / UnmergeSelection() |
SetSelectionOutline(color, width) / SetSelectionAllBorders(color, width) / ClearSelectionBorders() |
InsertRowsAtSelection() / DeleteSelectedRows() |
InsertColumnsAtSelection() / DeleteSelectedColumns() |
SetSelectedRowHeight(h) / SetSelectedColumnWidth(w) |
AutoFitSelectedColumns() / AutoFitSelectedRows() |
SetSelectionCellType(type) |
Clipboard
CopySelection() / CutSelection() / PasteClipboard()
Why the model does not hold the selection
V4 kept it on the model as worksheet.SelectionRange. V5 separates them so that showing one
worksheet through several views, and running headless, are both straightforward.
As a consequence, the selection is not saved to a file.
Keyboard
Arrow keys, Shift+arrow to extend, Ctrl+arrow to jump, Home / End and Page Up / Down are wired up by default.
viewport.StepTarget(dRow, dCol) only computes where a move would land, which is useful when
implementing your own key bindings.