Selection in UWP CellGrid (SfCellGrid)
10 May 20216 minutes to read
This section explains about the Selection behavior in SfCellGrid.
The SfCellGrid control provides support for selection in grid by using mouse, keyboard and touch interactions.
By default, Selection behavior will be enabled in SfCellGrid, but if you want to disable the selection in SfCellGrid, then set the AllowSelection
Property to be false.
cellGrid.AllowSelection = false;
Accessing the Current cell
SfCellGrid allows the user to access the active cell by using the CurrentCell
property of SelectionController
Class.
var cell = cellGrid.SelectionController.CurrentCell;
Accessing the Selected ranges
SfCellGrid allows the user to access the selected ranges list using the SelectedRanges
property.
var rangeList = cellGrid.SelectedRanges;
NOTE
To get the active range in the selected ranges list, use
ActiveRange
property ofGridRangeInfoList
class.
Adding or Clearing the Selection
SfCellGrid allows the user to add and clear the selection for the given range.
//To Add the Selection for range,
cellGrid.SelectionController. AddSelection(GridRangeInfo.Cells(4,6,5,8));
//To Add the Selection for row,
cellGrid.SelectionController.AddSelection(GridRangeInfo.Row(4));
//To Add the Selection for multiple rows,
cellGrid.SelectionController. AddSelection(GridRangeInfo.Rows(4,9));
//To Add the Selection for column,
cellGrid.SelectionController.AddSelection(GridRangeInfo.Col(5));
//To Add the Selection for multiple columns,
cellGrid.SelectionController. AddSelection(GridRangeInfo.Cols(5,10));
//To Clear the Selection,
cellGrid.SelectionController.ClearSelection();
Move Current Cell
SfCellGrid allows the user to move the current cell to the mentioned cell.
//Moves current cell to the mentioned row and column index of cell,
cellGrid.CurrentCell.MoveCurrentCell(5, 5);
Selection Attributes
SelectionBorderThickness
SfCellGrid allows the user to set the thickness of the border around the selected cells.
cellGrid.SelectionBorderThickness = 5;
SelectionBorderBrush
SfCellGrid allows the user to set the brush color of the border around the selected cells.
cellGrid.SelectionBorderBrush = new SolidColorBrush(Colors.DarkOliveGreen);
SelectionBrush
SfCellGrid allows the user to set the brush color for background of the selected cells.
cellGrid.SelectionBrush = new SolidColorBrush(Colors.Red);
Properties, Methods and Events
Below table lists the events associated with selection behavior,
Events | Description |
---|---|
CellClick
|
Occurs when you click on the cell. |
CurrentCellActivating
|
Occurs when the current cell is going to be activated. This event allows to cancel the current cell activation. |
CurrentCellActivated
|
Occurs after the current cell is activated. |
SelectionChanging
|
Occurs when the selection is going to be changed. This event allows to cancel the selection change. |
SelectionChanged
|
Occurs after the selection is changed. |
Below table lists the properties associated with selection,
Properties | Description |
---|---|
SelectedRanges
|
Gets or sets the collection of selected ranges from grid. |
SelectionBrush
|
Gets or sets the selected area brush. |
SelectionBorderBrush
|
Gets or sets the selection border brush. |
SelectionBorderThickness
|
Gets or sets the thickness of selection border. |
SelectionController
|
Gets the Selection Controller which provides the selection of content when the user drags the pressed mouse to an edge of the control. |
AllowSelection
|
Gets or Sets the value whether to allow the selection in the SfCellGrid or not. |
ShowTouchIndicator
|
Determines whether the touch indicator will be shown or not. |
TouchHitTestPrecision
|
Gets or sets the distance of touch precision point from touch indicator. |
Below table lists the properties associated with CurrentCell
,
Properties | Description |
---|---|
CellRowColumnIndex
|
Gets the row and column index of the Current Cell. |
RowIndex
|
Gets the row index of the Current Cell. |
ColumnIndex
|
Gets the column index of the Current Cell. |
Range
|
Gets the range of the Current Cell. |
HasCurrentCell
|
Gets the value indicating whether the Grid has Current Cell or not. |
PreviousRowColumnIndex
|
Gets or sets the row and column index of old Current Cell. |
Below table lists the methods associated with selection,
Methods | Description |
---|---|
AddSelection
|
Adds/Extends the Selection to the mentioned range. |
ClearSelection
|
Clears the Selection. |
MoveCurrentCell
|
Move the Current cell to mentioned row and column index. |
Key Navigation
Below table lists the key combinations associated with selection,
Key Combination | Description |
---|---|
HOME | Moves to the first cell of the current row. |
END | Moves to the last cell of the current row. |
UPARROW | Moves to one cell up of the current cell in the SfCellGrid. |
DOWNARROW | Moves to one cell down of the current cell in the SfCellGrid. |
LEFTARROW | Moves to one cell left of the current cell in the SfCellGrid. |
RIGHTARROW | Moves to one cell right of the current cell in the SfCellGrid. |
PAGEUP | Moves to the first visible cell of the current column. |
PAGEDOWN | Moves to the last visible cell of the current column. |
CTRL+HOME | Moves to the beginning cell of a SfCellGrid. |
CTRL+END | Moves to the last cell of a SfCellGrid. |
ALT+PAGE UP | Moves one screen to the left in a SfCellGrid. |
ALT+PAGE DOWN | Moves one screen to the right in a SfCellGrid. |
CTRL + ARROW KEYS | Moves to the first/last cell of the current cell based on Arrow directions. |
ENTER | Moves the active current cell to one cell down in the selection. |
SHIFT+ENTER | Moves the active current cell to one cell up in the selection. |
TAB | Moves the active current cell in one cell to the right of the selection. |
SHIFT+TAB | Moves the active current cell in one cell to the left of the selection. |
BACKSPACE | Begins the edit operation for the active cell in the selection. |
CTRL+A | Selects the entire worksheet. |
SHIFT+ARROW KEYS | Extends the selection by one cell based on the arrow direction. |
CTRL+SHIFT+ARROW KEYS | Extend the selection to the last cell in a row or column. |
SHIFT+HOME | Extends the selection to the first column from the active cell. |
CTRL+SHIFT+HOME | Extends the selection from the active cell to the first cell. |
SHIFT+PAGE DOWN | Extends the selection down in a SfCellGrid. |
SHIFT+PAGE UP | Extends the selection up in a SfCellGrid. |
Touch Selection Attributes
SfCellGrid provides support for touch selection.
ShowTouchIndicator
By default, the touch indicator is enabled in SfCellGrid. If you want to disable the indicator, then set the ShowTouchIndicator
to false.
cellGrid.SelectionController.ShowTouchIndicator = false;
TouchHitTestPrecision
TouchHitTestPrecision
property sets the distance of touch precision point from touch indicator. By default, it`s value is 10.
var point = cellGrid.SelectionController.TouchHitTestPrecision;