Skip to main content

ITreeSelectionModel Interface

Definition

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

Stores and manipulates the selection state of of items in a hierarchical data source.

public interface ITreeSelectionModel

Implements: INotifyPropertyChanged

Methods

NameDescription
BeginBatchUpdateBegins a batch update of the selection.
ClearClears the selection.
DeselectDeselects an item by its index in the source data.
EndBatchUpdateEnds a batch update started by Avalonia.Controls.Selection.ITreeSelectionModel.BeginBatchUpdate.
IsSelectedQueries whether an item is currently selected.
SelectSelects an item by its index in the source data.

BeginBatchUpdate Method

Begins a batch update of the selection.

public void BeginBatchUpdate()

Remarks

During a batch update no changes to the selection will be reflected in the model's properties and no events will be raised until Avalonia.Controls.Selection.ITreeSelectionModel.EndBatchUpdate is called.

Avalonia.Controls.Selection.ITreeSelectionModel.BeginBatchUpdate may be called multiple times, even when a batch update is already in progress; each call must have a corresponding call to Avalonia.Controls.Selection.ITreeSelectionModel.EndBatchUpdate in order to finish the operation.

Clear Method

Clears the selection.

public void Clear()

Deselect Method

Deselects an item by its index in the source data.

public void Deselect(Avalonia.Controls.IndexPath index)

Parameters

index Avalonia.Controls.IndexPath

The index into the source data.

EndBatchUpdate Method

Ends a batch update started by Avalonia.Controls.Selection.ITreeSelectionModel.BeginBatchUpdate.

public void EndBatchUpdate()

IsSelected Method

Queries whether an item is currently selected.

public bool IsSelected(Avalonia.Controls.IndexPath index)

Parameters

index Avalonia.Controls.IndexPath

The index of the item in the source data.

Returns

bool

True if the item is selected; otherwise false.

Select Method

Selects an item by its index in the source data.

public void Select(Avalonia.Controls.IndexPath index)

Parameters

index Avalonia.Controls.IndexPath

The index path of the item to select.

Remarks

If Avalonia.Controls.Selection.ITreeSelectionModel.SingleSelect is true, this method will clear any existing selection before selecting the specified item.

If the item is already selected, this method does nothing.

Properties

NameDescription
AnchorIndexGets or sets the anchor index.
CountGets the number of selected items.
RangeAnchorIndexGets or sets the range anchor index.
SelectedIndexGets or sets the selected index within the data.
SelectedIndexesGets the indexes of the selected items.
SelectedItemGets the selected item.
SelectedItemsGets the selected items.
SingleSelectGets or sets a value indicating whether the model supports single or multiple selection.
SourceGets or sets the root of the hierarchical data.

AnchorIndex Property

Gets or sets the anchor index.

public Avalonia.Controls.IndexPath AnchorIndex { get; set; }

Remarks

The anchor index holds the index of the item from which non-ranged keyboard selection will start, i.e. in a vertical list it will hold the item from which selection should be moved by pressing the up or down arrow key. This is usually the last selected item.

Avalonia.Controls.Selection.ITreeSelectionModel.AnchorIndex is automatically set when selecting an item via Avalonia.Controls.Selection.ITreeSelectionModel.SelectedIndex or Avalonia.Controls.Selection.ITreeSelectionModel.Select(Avalonia.Controls.IndexPath).

Count Property

Gets the number of selected items.

public int Count { get; set; }

RangeAnchorIndex Property

Gets or sets the range anchor index.

public Avalonia.Controls.IndexPath RangeAnchorIndex { get; set; }

Remarks

The range anchor index holds the index of the item from which ranged selection will start, i.e. when shift-clicking an item it represents the start of the range to be selected whereas the shift-clicked item will be the end of the range.

Avalonia.Controls.Selection.ITreeSelectionModel.RangeAnchorIndex is set when selecting an item via Avalonia.Controls.Selection.ITreeSelectionModel.SelectedIndex but not via Avalonia.Controls.Selection.ITreeSelectionModel.Select(Avalonia.Controls.IndexPath).

SelectedIndex Property

Gets or sets the selected index within the data.

public Avalonia.Controls.IndexPath SelectedIndex { get; set; }

Remarks

Setting this property clears any existing selection and selects only the item at the specified index path. When multiple items are selected, this property represents the first selected item.

SelectedIndexes Property

Gets the indexes of the selected items.

public System.Collections.Generic.IReadOnlyList<Avalonia.Controls.IndexPath> SelectedIndexes { get; set; }

SelectedItem Property

Gets the selected item.

public object SelectedItem { get; set; }

Remarks

In the case of multiple selected items, returns the item that was first selected.

SelectedItems Property

Gets the selected items.

public System.Collections.Generic.IReadOnlyList<object> SelectedItems { get; set; }

SingleSelect Property

Gets or sets a value indicating whether the model supports single or multiple selection.

public bool SingleSelect { get; set; }

Source Property

Gets or sets the root of the hierarchical data.

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

Events

NameDescription
IndexesChangedOccurs when the indexes of the selected items are changed due to items being added or removed from the source data.
SelectionChangedOccurs when the selection changes due to items being selected/deselected, or selected items being removed from the source.
SourceResetOccurs when a System.Collections.Specialized.NotifyCollectionChangedAction.Reset signal is retreived on the source data.

IndexesChanged Event

Occurs when the indexes of the selected items are changed due to items being added or removed from the source data.

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

SelectionChanged Event

Occurs when the selection changes due to items being selected/deselected, or selected items being removed from the source.

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

Remarks

Note that due to limitations of the System.Collections.Specialized.INotifyCollectionChanged feature in the .NET BCL, this event will not be raised when a System.Collections.Specialized.NotifyCollectionChangedAction.Reset signal is retreived due to e.g. calling System.Collections.IList.Clear on an System.Collections.ObjectModel.ObservableCollection<T>. For this reason it is advised that all subscriptions to Avalonia.Controls.Selection.ITreeSelectionModel.SelectionChanged are paired with a subscription to Avalonia.Controls.Selection.ITreeSelectionModel.SourceReset. ///

SourceReset Event

Occurs when a System.Collections.Specialized.NotifyCollectionChangedAction.Reset signal is retreived on the source data.

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