GridSelection
public sealed class GridSelection
Namespace SharpCell.Grid · package SharpCell.Grid
The selected cells, as in Excel: a rectangle of cells and the active cell inside it. The rectangle runs from the GridSelection.Anchor, where the selection started, to the GridSelection.Extent, the corner the mouse or Shift with the arrows moves, and grows to cover whole every merged area it touches. Whole columns span every row of the sheet, whole rows every column. A selection never changes; each step gives a new one.
Properties
ActiveCell
public CellPosition ActiveCell { get; }
The cell typing would go into, with the white background inside the shaded selection.
Anchor
public CellPosition Anchor { get; }
The corner the selection started from; it stays when the selection is extended.
Area
public CellArea Area { get; }
The selected cells, merged areas they touch included.
Extent
public CellPosition Extent { get; }
The corner opposite the anchor, which extending the selection moves.
IsEntireColumns
public bool IsEntireColumns { get; }
Whether the selection spans every row: whole columns, or the whole sheet.
IsEntireRows
public bool IsEntireRows { get; }
Whether the selection spans every column: whole rows, or the whole sheet.
IsSingleCell
public bool IsSingleCell { get; }
Whether only the active cell is selected; a merged area counts as one cell.
Methods
All(CellPosition)
public static GridSelection All(CellPosition activeCell)
The whole sheet, keeping the active cell where it is.
At(GridHit, Worksheet)
public static GridSelection At(GridHit hit, Worksheet? sheet)
What a click selects: a cell, whole columns from a column header, whole rows from a row header, the whole sheet from the corner above the row headers.
Cell(CellPosition, Worksheet)
public static GridSelection Cell(CellPosition cell, Worksheet? sheet)
One cell, or the merged area holding it.
Columns(int, int, int, Worksheet)
public static GridSelection Columns(int first, int last, int activeRow, Worksheet? sheet)
Whole columns, from the first to the last, with the active cell in the first column.
Parameters
first: The column the selection starts from.last: The column it extends to; beforefirstfor a selection extended to the left.activeRow: The row of the active cell: in Excel, the top row on screen.sheet: The sheet, whose merged areas the selection covers whole.
Contains(int, int)
public bool Contains(int row, int column)
Whether a cell is selected.
EntireColumns(Worksheet)
public GridSelection EntireColumns(Worksheet? sheet)
Whole columns under the selection, keeping the active cell, as Ctrl+Space does.
EntireRows(Worksheet)
public GridSelection EntireRows(Worksheet? sheet)
Whole rows under the selection, keeping the active cell, as Shift+Space does.
Extend(int, int, Worksheet)
public GridSelection Extend(int rows, int columns, Worksheet? sheet)
The selection grown or shrunk by whole rows and columns at its extent, as Shift with the arrows does; a step that a merged area swallows goes on until the selection changes.
ExtendTo(CellPosition, Worksheet)
public GridSelection ExtendTo(CellPosition cell, Worksheet? sheet)
The selection from the same anchor to a cell, as when dragging the mouse or Shift-clicking: whole columns or rows stay whole, the active cell stays.
ExtendTo(GridHit, Worksheet)
public GridSelection ExtendTo(GridHit hit, Worksheet? sheet)
The selection from the same anchor to what a Shift-click hits: to a cell, to whole columns from a column header, to whole rows from a row header, the whole sheet from the corner.
ExtendToEdge(int, int, Worksheet)
public GridSelection ExtendToEdge(int rows, int columns, Worksheet? sheet)
The selection extended from its far corner to the edge of the content, as Ctrl+Shift with an arrow does.
Parameters
rows: -1 up, 1 down, or 0.columns: -1 left, 1 right, or 0.sheet: The sheet whose content decides the edge; see GridNavigation.MoveToEdge.
Move(int, int, Worksheet)
public GridSelection Move(int rows, int columns, Worksheet? sheet)
The active cell moved by whole rows and columns, as the arrows move it, and selected alone.
MoveToEdge(int, int, Worksheet)
public GridSelection MoveToEdge(int rows, int columns, Worksheet? sheet)
The active cell moved to the edge of the content, as Ctrl with an arrow moves it, and selected alone.
Parameters
rows: -1 up, 1 down, or 0.columns: -1 left, 1 right, or 0.sheet: The sheet whose content decides the edge; see GridNavigation.MoveToEdge.
MoveWithin(int, int, Worksheet)
public GridSelection MoveWithin(int rows, int columns, Worksheet? sheet)
The active cell moved as Enter and Tab move it. A single cell moves as with the arrows; inside a larger selection it moves to the next cell of the selection, which stays, and wraps around: Enter goes down each column in turn, Tab across each row. Hidden cells and the inner cells of merged areas are passed over.
Parameters
rows: 1 for Enter, -1 for Shift+Enter, 0 for Tab.columns: 1 for Tab, -1 for Shift+Tab, 0 for Enter.sheet: The sheet, whose hidden rows and columns and merged areas are passed over.
Rows(int, int, int, Worksheet)
public static GridSelection Rows(int first, int last, int activeColumn, Worksheet? sheet)
Whole rows, from the first to the last, with the active cell in the first row.
Parameters
first: The row the selection starts from.last: The row it extends to; abovefirstfor a selection extended upwards.activeColumn: The column of the active cell: in Excel, the leftmost column on screen.sheet: The sheet, whose merged areas the selection covers whole.
SelectAll(Worksheet)
public GridSelection SelectAll(Worksheet? sheet)
What Ctrl+A selects, as in Excel: first the current region around the active cell (see GridNavigation.CurrentRegion), then, pressed again, the whole sheet. An empty cell with nothing around it, or a lone cell, goes straight to the whole sheet. The active cell stays.
Parameters
sheet: The sheet whose content makes the region.
ToString()
public override string ToString()
The selected cells' address: B3, B3:D7, C:E for whole columns, 2:4 for whole rows.