<!-- Generated by tools/SharpCell.Grid.Docs from the XML documentation comments. Do not edit; run the tool with 'generate'. -->

# GridSelection

```csharp
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](SharpCell.Grid.GridSelection.md#anchor), where the selection started, to the [GridSelection.Extent](SharpCell.Grid.GridSelection.md#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

<a id="activecell"></a>
### ActiveCell

```csharp
public CellPosition ActiveCell { get; }
```

The cell typing would go into, with the white background inside the shaded selection.

<a id="anchor"></a>
### Anchor

```csharp
public CellPosition Anchor { get; }
```

The corner the selection started from; it stays when the selection is extended.

<a id="area"></a>
### Area

```csharp
public CellArea Area { get; }
```

The selected cells, merged areas they touch included.

<a id="extent"></a>
### Extent

```csharp
public CellPosition Extent { get; }
```

The corner opposite the anchor, which extending the selection moves.

<a id="isentirecolumns"></a>
### IsEntireColumns

```csharp
public bool IsEntireColumns { get; }
```

Whether the selection spans every row: whole columns, or the whole sheet.

<a id="isentirerows"></a>
### IsEntireRows

```csharp
public bool IsEntireRows { get; }
```

Whether the selection spans every column: whole rows, or the whole sheet.

<a id="issinglecell"></a>
### IsSingleCell

```csharp
public bool IsSingleCell { get; }
```

Whether only the active cell is selected; a merged area counts as one cell.

## Methods

<a id="all-cellposition"></a>
### All(CellPosition)

```csharp
public static GridSelection All(CellPosition activeCell)
```

The whole sheet, keeping the active cell where it is.

<a id="at-gridhit-worksheet"></a>
### At(GridHit, Worksheet)

```csharp
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.

<a id="cell-cellposition-worksheet"></a>
### Cell(CellPosition, Worksheet)

```csharp
public static GridSelection Cell(CellPosition cell, Worksheet? sheet)
```

One cell, or the merged area holding it.

<a id="columns-int-int-int-worksheet"></a>
### Columns(int, int, int, Worksheet)

```csharp
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; before `first` for 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.

<a id="contains-int-int"></a>
### Contains(int, int)

```csharp
public bool Contains(int row, int column)
```

Whether a cell is selected.

<a id="entirecolumns-worksheet"></a>
### EntireColumns(Worksheet)

```csharp
public GridSelection EntireColumns(Worksheet? sheet)
```

Whole columns under the selection, keeping the active cell, as Ctrl+Space does.

<a id="entirerows-worksheet"></a>
### EntireRows(Worksheet)

```csharp
public GridSelection EntireRows(Worksheet? sheet)
```

Whole rows under the selection, keeping the active cell, as Shift+Space does.

<a id="extend-int-int-worksheet"></a>
### Extend(int, int, Worksheet)

```csharp
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.

<a id="extendto-cellposition-worksheet"></a>
### ExtendTo(CellPosition, Worksheet)

```csharp
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.

<a id="extendto-gridhit-worksheet"></a>
### ExtendTo(GridHit, Worksheet)

```csharp
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.

<a id="extendtoedge-int-int-worksheet"></a>
### ExtendToEdge(int, int, Worksheet)

```csharp
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](SharpCell.Grid.GridNavigation.md#movetoedge-worksheet-cellposition-int-int).

<a id="move-int-int-worksheet"></a>
### Move(int, int, Worksheet)

```csharp
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.

<a id="movetoedge-int-int-worksheet"></a>
### MoveToEdge(int, int, Worksheet)

```csharp
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](SharpCell.Grid.GridNavigation.md#movetoedge-worksheet-cellposition-int-int).

<a id="movewithin-int-int-worksheet"></a>
### MoveWithin(int, int, Worksheet)

```csharp
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.

<a id="rows-int-int-int-worksheet"></a>
### Rows(int, int, int, Worksheet)

```csharp
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; above `first` for 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.

<a id="selectall-worksheet"></a>
### SelectAll(Worksheet)

```csharp
public GridSelection SelectAll(Worksheet? sheet)
```

What Ctrl+A selects, as in Excel: first the current region around the active cell (see [GridNavigation.CurrentRegion](SharpCell.Grid.GridNavigation.md#currentregion-worksheet-cellposition)), 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.

<a id="tostring"></a>
### ToString()

```csharp
public override string ToString()
```

The selected cells' address: `B3`, `B3:D7`, `C:E` for whole columns, `2:4` for whole rows.
