Selection and clipboard

Selection works on cells or on whole rows, in one range or several. Copy, paste, cut, clear and fill-down act on it the way a spreadsheet does, and every write goes through the same checks as typing.

Cells or rows

Selection mode
grid.SelectionMode = SelectionMode.Row;      // whole rows; the default is SelectionMode.Cell
view.WithRowSelector();                      // the thin selection lane on the left

In Cell mode a selection is one or more rectangles of cells; in Row mode it is whole rows. Api.Selection.Mode and the control's SelectionMode property are the same setting; ModeChanged reports a switch.

With the mouse and the keyboard

GestureSelects
Click, arrow keysOne cell, which is also the current cell.
Shift+click, Shift+arrows, dragExtends the range from the anchor.
Ctrl+clickKeeps the current range and starts another.
Shift+SpaceThe whole row of the current cell.
Ctrl+SpaceThe whole column of the current cell.
Ctrl+AEverything.
EscClears the selection.

From code

Api.Selection
var selection = grid.Api.Selection;

selection.Set(item: 0, column: 1);                     // one cell, also the current cell
selection.SetRange(0, 0, 9, 3);                        // a block: rows 0-9, columns 0-3
selection.BeginAdditionalRange(20, 0);                 // a second range, as with Ctrl+click
selection.ExtendTo(24, 3, keepExisting: true);         // keeps the first range
selection.SetSelectedItems(new[] { order });           // by item, whatever the sort order

object? current = selection.CurrentItem;
IReadOnlyList<object> items = selection.Items;         // the selected rows' items
selection.Changed += () => Log($"{selection.RowCount} rows selected");

Positions here are view rows and visible column indexes. When you know the item but not where the current sort put it, use SetSelectedItems or SetCurrentItem; Ranges and RowIntervals describe the selection as rectangles and as row intervals. Api.Events.SelectionChanged carries the current cell, the selected items and the ranges in one argument.

On the controls, SelectedItem, SelectedItems, CurrentItem and CurrentCell are bindable and two-way by default.

While a selection spans more than one cell, a footer under the grid says how much is selected and, when the selection covers summable cells, their sum. It can carry buttons: the grid draws them and reports the click, what they do is yours.

Footer actions
grid.Api.State.ShowSelectionFooter = true;
grid.Api.State.SelectionActions =
[
    new SelectionAction("Archive", FooterActionStyle.Outline, () => Archive(selection.Items)),
    new SelectionAction("Delete", FooterActionStyle.Danger, () => Log("delete")),
];

Copy, paste, cut

KeyWhat it does
Ctrl+C, Ctrl+InsertCopies the selection as tab-separated text.
Ctrl+Shift+CThe same, with the column captions as the first line.
Ctrl+V, Shift+InsertPastes into the selection.
Ctrl+XCopies, then clears the editable cells.
DeleteClears the editable cells of the selection.
Ctrl+DFills the top row of the selection down.

Paste reads tab-separated text — rows split on line breaks, columns on tabs — anchored at the top-left of the selection. A single value fills the whole selection; a block is written from the anchor and clipped at the grid's edge. Cells that are read-only, or that refuse the value, are skipped and keep theirs. The whole paste is one undo step.

Inside an open editor or a filter box, the same keys work on the text instead.

The same from code
grid.Api.Commands.Copy();                       // Ctrl+C: tab-separated text
grid.Api.Commands.Copy(withHeaders: true);      // Ctrl+Shift+C: with the column captions
grid.Api.Commands.RequestPaste();               // Ctrl+V: the host reads the clipboard
grid.Api.Commands.Clear();                      // Delete: clears the editable cells

grid.Api.Events.SelectionOperationRejected += e =>
    Log($"{e.Operation} refused: {e.Reason}");

Some selections cannot be copied or pasted sensibly — several ranges of different shapes, overlapping target ranges, a selection beyond the copy limit. The grid then does nothing and raises SelectionOperationRejected with the operation (Copy, Paste, Clear) and the reason (IrregularMultiRangeSelection, IncompatibleTargetRanges, OverlappingTargetRanges, SelectionTooLarge).