Skip to main content

TreeDataGridSelectionModel Class

Definition

Assembly:Avalonia.Controls.TreeDataGrid
Package:Avalonia.Controls.TreeDataGrid

Base class for selection models in TreeDataGrid.

public class TreeDataGridSelectionModel

Inheritance: object -> TreeDataGridSelectionModel

Implements: INotifyPropertyChanged

Properties

NameDescription
IsCellSelectionModelGets a value indicating whether this is a cell selection model.
SingleSelectGets or sets a value indicating whether only a single item can be selected at a time.
SourceGets the data source for the selection model.

IsCellSelectionModel Property

Gets a value indicating whether this is a cell selection model.

public bool IsCellSelectionModel { get; set; }

SingleSelect Property

Gets or sets a value indicating whether only a single item can be selected at a time.

public bool SingleSelect { get; set; }

Source Property

Gets the data source for the selection model.

public System.Collections.IEnumerable Source { get; set; }

Events

NameDescription
IndexesChangedOccurs when item indexes change due to insertions or removals in the data source.
PropertyChangedNo summary available.
SelectionChangedOccurs when the selection changes, providing unified event args with row and cell index information.
SourceResetOccurs when the data source is reset.

IndexesChanged Event

Occurs when item indexes change due to insertions or removals in the data source.

public event EventHandler<Avalonia.Controls.Selection.TreeDataGridIndexesChangedEventArgs> IndexesChanged

PropertyChanged Event

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged

SelectionChanged Event

Occurs when the selection changes, providing unified event args with row and cell index information.

public event EventHandler<Avalonia.Controls.Selection.TreeDataGridSelectionChangedEventArgs> SelectionChanged

SourceReset Event

Occurs when the data source is reset.

public event EventHandler<Avalonia.Controls.Selection.TreeDataGridItemsResetEventArgs> SourceReset

Remarks

This event is raised when a collection in the hierarchical data structure is reset, such as when a collection is cleared or replaced with a new collection.

Due to design limitations of collection reset events, the selection model cannot automatically preserve selection state when a collection is reset. The reset event doesn't provide information about which items were removed or how they map to new items.

Applications that need to maintain selection across collection resets must handle this event and manually restore the selection based on their knowledge of the data model. For example, you might store the IDs or unique identifiers of selected items before the reset, and then re-select them after the reset by finding the new indices of those items.

The Avalonia.Controls.Selection.TreeDataGridItemsResetEventArgs.ParentIndex property indicates which part of the hierarchical structure was reset, allowing you to determine whether to restore selection for the entire collection or just a subtree.