Class TreeGridSelectionController
Handles selection operations for the TreeGrid control.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.Maui.TreeGrid
Assembly: Syncfusion.Maui.TreeGrid.dll
Syntax
public abstract class TreeGridSelectionController : IDisposable
Remarks
This controller manages row selection state, enforces selection mode constraints, and maintains selection persistence across tree mutations and virtualization. Selection is tracked by tree node identity, not transient row indices. Derive from this class (or TreeGridRowSelectionController) and assign it to SelectionController to customize keyboard navigation and selection behavior.
Constructors
TreeGridSelectionController(SfTreeGrid?)
Initializes a new instance of the TreeGridSelectionController class.
Declaration
public TreeGridSelectionController(SfTreeGrid? treeGrid)
Parameters
| Type | Name | Description |
|---|---|---|
| SfTreeGrid | treeGrid | The TreeGrid instance. |
Fields
currentRow
Holds the row information of the current row.
Declaration
protected TreeGridRowInfo? currentRow
Field Value
| Type |
|---|
| TreeGridRowInfo |
currentRowIndex
Holds the row index of the current row.
Declaration
protected int currentRowIndex
Field Value
| Type |
|---|
| int |
Properties
CurrentCellIndex
Gets the current cell index in the SfTreeGrid.
Declaration
protected RowColumnIndex CurrentCellIndex { get; }
Property Value
| Type |
|---|
| RowColumnIndex |
IsCommandKeyPressed
Gets or sets a value indicating whether the Command key is pressed during selection operation.
Declaration
public bool IsCommandKeyPressed { get; }
Property Value
| Type |
|---|
| bool |
Remarks
This property is used to track Command key state for selection operations on macOS and iOS platforms.
IsCtrlKeyPressed
Gets or sets a value indicating whether the Ctrl key is pressed during selection operation.
Declaration
public bool IsCtrlKeyPressed { get; }
Property Value
| Type |
|---|
| bool |
IsShiftKeyPressed
Gets or sets a value indicating whether the Shift key is pressed during selection operation.
Declaration
public bool IsShiftKeyPressed { get; }
Property Value
| Type |
|---|
| bool |
SelectedRows
Gets a list of all selected row data items.
Declaration
public ObservableCollection<TreeGridRowInfo> SelectedRows { get; set; }
Property Value
| Type |
|---|
| ObservableCollection<TreeGridRowInfo> |
TreeGrid
Gets the reference of the SfTreeGrid.
Declaration
protected SfTreeGrid? TreeGrid { get; }
Property Value
| Type |
|---|
| SfTreeGrid |
Methods
ApplySelection(int)
Applies the selection to the specified row index based on the current selection mode.
Declaration
protected abstract bool ApplySelection(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index in which the selection is applied. |
Returns
| Type | Description |
|---|---|
| bool | True if the selection is applied; otherwise, false. |
ClearSelection()
Clears the current selection.
Declaration
public virtual bool ClearSelection()
Returns
| Type | Description |
|---|---|
| bool | True if the selection is cleared; otherwise, false. |
CreateRowInfo(int)
Creates the row information for the specified row index.
Declaration
protected TreeGridRowInfo? CreateRowInfo(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index. |
Returns
| Type | Description |
|---|---|
| TreeGridRowInfo | The TreeGridRowInfo for the specified row; otherwise, null. |
Dispose()
Performs final clean up before it is released from memory.
Declaration
public void Dispose()
Dispose(bool)
Releases the unmanaged resources used by the component and optionally releases the managed resources.
Declaration
protected virtual void Dispose(bool isDisposing)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | isDisposing | if true - release both managed and unmanaged resources; if false - release only unmanaged resources. |
GetFirstColumnIndex()
Gets the index of the first column that can be navigated to in the SfTreeGrid. Skips columns where AllowFocus is false.
Declaration
protected int GetFirstColumnIndex()
Returns
| Type | Description |
|---|---|
| int | The first navigable column index. |
GetFirstDataRowIndex()
Gets the index of the first data row that can be navigated to in the SfTreeGrid.
Declaration
protected int GetFirstDataRowIndex()
Returns
| Type | Description |
|---|---|
| int | The first navigable row index. |
GetLastColumnIndex()
Gets the index of the last navigable column in the SfTreeGrid. Skips columns where AllowFocus is false.
Declaration
protected int GetLastColumnIndex()
Returns
| Type | Description |
|---|---|
| int | The last navigable column index. |
GetLastNavigatingRowIndex()
Gets the index of the last data row that can be navigated to in the SfTreeGrid.
Declaration
protected int GetLastNavigatingRowIndex()
Returns
| Type | Description |
|---|---|
| int | The last navigable row index. |
GetNextFocusableColumnIndex(int)
Gets the next focusable column index from the specified column. Skips columns where AllowFocus is false.
Declaration
protected int GetNextFocusableColumnIndex(int currentColumnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | currentColumnIndex | The current column index. |
Returns
| Type | Description |
|---|---|
| int | The next focusable column index, or the current index if none found. |
GetPreviousFocusableColumnIndex(int)
Gets the previous focusable column index from the specified column. Skips columns where AllowFocus is false.
Declaration
protected int GetPreviousFocusableColumnIndex(int currentColumnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | currentColumnIndex | The current column index. |
Returns
| Type | Description |
|---|---|
| int | The previous focusable column index, or the current index if none found. |
GetVisibleLineCount()
Gets the count of data rows currently visible in the view.
Declaration
protected int GetVisibleLineCount()
Returns
| Type | Description |
|---|---|
| int | The visible data row count. |
IsSelectedRow(TreeNode?, object?)
Gets a value indicating whether the specified row is selected.
Declaration
public virtual bool IsSelectedRow(TreeNode? treeNode, object? rowData)
Parameters
| Type | Name | Description |
|---|---|---|
| TreeNode | treeNode | The tree node associated with the row. |
| object | rowData | The row data associated with the row. |
Returns
| Type | Description |
|---|---|
| bool | True if the row is selected; otherwise, false. |
MoveCurrentCell(int)
Moves the current cell or current row to the specified row index.
Declaration
protected void MoveCurrentCell(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index to move the current cell or current row to. |
MoveCurrentCell(int, int)
Moves the current cell or current row to the specified row and column index.
Declaration
protected void MoveCurrentCell(int rowIndex, int columnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index to move the current cell or current row to. |
| int | columnIndex | The column index to move the current cell to. |
ProcessCtrlEndKey()
Processes the Ctrl+End key navigation.
Declaration
protected virtual void ProcessCtrlEndKey()
ProcessCtrlHomeKey()
Processes the Ctrl+Home key navigation.
Declaration
protected virtual void ProcessCtrlHomeKey()
ProcessDeleteKey()
Processes the Delete key by deleting the selected rows when deletion is supported.
Declaration
protected virtual void ProcessDeleteKey()
ProcessDownKey(int)
Processes the Down arrow key and Enter key navigation.
Declaration
protected virtual void ProcessDownKey(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index to navigate to. |
ProcessEndKey(int)
Processes the End key navigation.
Declaration
protected virtual void ProcessEndKey(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The current row index. |
ProcessHomeKey(int)
Processes the Home key navigation.
Declaration
protected virtual void ProcessHomeKey(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The current row index. |
ProcessLeftKey(int, int)
Processes the Left arrow key navigation in Cell mode. Skips columns where AllowFocus is false.
Declaration
protected virtual void ProcessLeftKey(int rowIndex, int columnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index of the current cell. |
| int | columnIndex | The current column index. |
ProcessPageDownKey()
Processes the Page Down key navigation, scrolling to the next set of rows not currently visible.
Declaration
protected virtual void ProcessPageDownKey()
ProcessPageUpKey()
Processes the Page Up key navigation, scrolling to the previous set of rows not currently visible.
Declaration
protected virtual void ProcessPageUpKey()
ProcessRightKey(int, int)
Processes the Right arrow key navigation in Cell mode. Skips columns where AllowFocus is false.
Declaration
protected virtual void ProcessRightKey(int rowIndex, int columnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index of the current cell. |
| int | columnIndex | The current column index. |
ProcessSpaceKey()
Processes the Space key for row selection.
Declaration
protected virtual void ProcessSpaceKey()
Remarks
Override this method in a derived class to customize Space key behavior. The default implementation is intentionally empty; derived classes like TreeGridRowSelectionController should provide the full implementation.
ProcessUpKey(int)
Processes the Up arrow key navigation.
Declaration
protected virtual void ProcessUpKey(int rowIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The row index to navigate to. |
RaiseCurrentCellActivated(RowColumnIndex, RowColumnIndex)
Raises the CurrentCellActivated event for the TreeGrid control.
Declaration
protected void RaiseCurrentCellActivated(RowColumnIndex currentCell, RowColumnIndex previousCurrentCell)
Parameters
| Type | Name | Description |
|---|---|---|
| RowColumnIndex | currentCell | The index of the currently activated cell. |
| RowColumnIndex | previousCurrentCell | The index of the previously activated cell. |
RaiseCurrentCellActivating(RowColumnIndex, RowColumnIndex)
Raises the CurrentCellActivating event for the TreeGrid control.
Declaration
protected bool RaiseCurrentCellActivating(RowColumnIndex currentCell, RowColumnIndex previousCurrentCell)
Parameters
| Type | Name | Description |
|---|---|---|
| RowColumnIndex | currentCell | |
| RowColumnIndex | previousCurrentCell |
Returns
| Type |
|---|
| bool |
RaiseSelectionChanged(IList, IList)
Raises the SelectionChanged event.
Declaration
protected void RaiseSelectionChanged(IList addedRows, IList removedRows)
Parameters
| Type | Name | Description |
|---|---|---|
| IList | addedRows | The list of added rows. |
| IList | removedRows | The list of removed rows. |
RaiseSelectionChanging(IList, IList)
Raises the SelectionChanging event.
Declaration
protected bool RaiseSelectionChanging(IList addedRows, IList removedRows)
Parameters
| Type | Name | Description |
|---|---|---|
| IList | addedRows | The list of added rows. |
| IList | removedRows | The list of removed rows. |
Returns
| Type | Description |
|---|---|
| bool | True if the selection can proceed; otherwise, false. |
SelectAll()
Selects all rows in the TreeGrid based on the current selection mode.
Declaration
public abstract bool SelectAll()
Returns
| Type | Description |
|---|---|
| bool | True if the rows are selected; otherwise, false. |
SelectCellRange(RowColumnIndex, bool)
Selects the range of cells between the anchor (PressedRowColumnIndex) and the specified row column index.
When preserveExistingSelection is true, previously selected cells outside the
rectangular range are retained (Ctrl+Shift behavior); otherwise they are removed (Shift behavior).
Declaration
protected virtual bool SelectCellRange(RowColumnIndex endRowColumnIndex, bool preserveExistingSelection)
Parameters
| Type | Name | Description |
|---|---|---|
| RowColumnIndex | endRowColumnIndex | The row column index to extend the selection to. |
| bool | preserveExistingSelection | Indicates whether to keep previous selections outside the range. |
Returns
| Type | Description |
|---|---|
| bool | True if the range selection is applied; otherwise, false. |
SelectRowRange(int, bool)
Selects a range of rows between the anchor (PressedRowColumnIndex) and the specified row index.
When preserveExistingSelection is true, previously selected rows outside
the range are retained (Ctrl+Shift behavior); otherwise they are removed (Shift behavior),
mirroring SfDataGrid ProcessShiftSelection.
Declaration
protected virtual bool SelectRowRange(int endIndex, bool preserveExistingSelection)
Parameters
| Type | Name | Description |
|---|---|---|
| int | endIndex | The row index to extend the selection to. |
| bool | preserveExistingSelection | Indicates whether to keep previous selections outside the range. |
Returns
| Type | Description |
|---|---|
| bool | True if the range selection is applied; otherwise, false. |
TryExtendSelectionTo(int, int)
Extends the selection from the anchor to the target index when Shift is held in Extended mode, then moves the current cell. No-op for other modes.
Declaration
protected bool TryExtendSelectionTo(int rowIndex, int columnIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | rowIndex | The target row index. |
| int | columnIndex | The target column index. |
Returns
| Type | Description |
|---|---|
| bool | True if the selection was extended; otherwise, false. |