Use cell selection when interactions should target individual cells rather than whole rows.
using Avalonia.Controls.Selection;
Source.Selection = new TreeDataGridCellSelectionModel<Person>(Source)
{
SingleSelect = false,
};
When active, source exposes:
Source.CellSelectionSource.CellSelection!.SelectedIndex = new CellIndex(
columnIndex: 2,
rowIndex: new IndexPath(0, 1));
Read selection:
var current = Source.CellSelection!.SelectedIndex;
var all = Source.CellSelection.SelectedIndexes;
Source.CellSelection!.SetSelectedRange(
start: new CellIndex(1, new IndexPath(0)),
columnCount: 3,
rowCount: 5);
This clears existing selection and selects a rectangular range.
Source.CellSelection!.SelectionChanged += (_, e) =>
{
// event fired when selected cells change
};
For control-level visuals, TreeDataGrid routes selection interaction updates to realized rows/cells.
var isSelected = Source.CellSelection!.IsSelected(new CellIndex(0, new IndexPath(2)));
Cell model handles:
Behavior is implemented through ITreeDataGridSelectionInteraction.
RowSelectionCellIndex with model index that is not currently represented in sourceSetSelectedRange replaces selectionFeature behavior differs from expectations
Cause: one or more options in this scenario are configured differently (source type, column options, sort/selection/edit state).
Fix: compare your setup with the snippet in this article and verify runtime values on Source, Columns, and Selection.
Data changes are not visible in UI
Cause: model or collection notifications are missing, or a replaced collection/source is not re-bound.
Fix: ensure INotifyPropertyChanged/INotifyCollectionChanged flow is active and reassign Source after replacing underlying collections.