# SelectionModel

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/selection/struct-selectionmodel/

**struct** · [`ferroui-controls`](/docs/0.5.0/api/ferroui-controls/) · v0.5.0

```rust
struct SelectionModel<T: PropertyValue>
```

A selection model: the selection of the items of a source collection of
items of type `T`. The untyped model is `SelectionModel<BoxedValue>`.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L160)

## Members

- [`new`](#function-new)
- [`with_source`](#function-with_source)
- [`set_derived`](#function-set_derived)
- [`node`](#function-node)
- [`source`](#function-source)
- [`set_source`](#function-set_source)
- [`single_select`](#function-single_select)
- [`set_single_select`](#function-set_single_select)
- [`selected_index`](#function-selected_index)
- [`set_selected_index`](#function-set_selected_index)
- [`selected_indexes`](#function-selected_indexes)
- [`selected_item`](#function-selected_item)
- [`set_selected_item`](#function-set_selected_item)
- [`selected_items`](#function-selected_items)
- [`anchor_index`](#function-anchor_index)
- [`set_anchor_index`](#function-set_anchor_index)
- [`count`](#function-count)
- [`indexes_changed`](#function-indexes_changed)
- [`selection_changed`](#function-selection_changed)
- [`lost_selection`](#function-lost_selection)
- [`source_reset`](#function-source_reset)
- [`batch_update`](#function-batch_update)
- [`begin_batch_update`](#function-begin_batch_update)
- [`end_batch_update`](#function-end_batch_update)
- [`is_selected`](#function-is_selected)
- [`select`](#function-select)
- [`deselect`](#function-deselect)
- [`select_range`](#function-select_range)
- [`deselect_range`](#function-deselect_range)
- [`select_all`](#function-select_all)
- [`clear`](#function-clear)
- [`raise_property_changed`](#function-raise_property_changed)
- [`base_set_source`](#function-base_set_source)
- [`base_on_indexes_changed`](#function-base_on_indexes_changed)
- [`base_on_source_collection_change_started`](#function-base_on_source_collection_change_started)
- [`base_on_source_reset`](#function-base_on_source_reset)
- [`base_on_selection_removed`](#function-base_on_selection_removed)
- [`base_on_items_added`](#function-base_on_items_added)
- [`base_on_items_removed`](#function-base_on_items_removed)
- [`base_on_source_collection_changed`](#function-base_on_source_collection_changed)
- [`base_is_valid_collection_change`](#function-base_is_valid_collection_change)
- [`base_on_source_collection_change_finished`](#function-base_on_source_collection_change_finished)

<a id="function-new"></a>

### new

```rust
fn new() -> Rc<Self>
```

Creates a selection model without a source.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L183)

<a id="function-with_source"></a>

### with_source

```rust
fn with_source(source: Option<ItemsSource>) -> Rc<Self>
```

Creates a selection model for a source.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L210)

<a id="function-set_derived"></a>

### set_derived

```rust
fn set_derived(self: &Self, derived: Weak<dyn SelectionModelImpl<T>>)
```

Registers the object deriving from this model, which receives the
virtual calls (see `SelectionModelImpl`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L218)

<a id="function-node"></a>

### node

```rust
fn node(self: &Self) -> &SelectionNodeBase<T>
```

The base state of the model.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L227)

<a id="function-source"></a>

### source

```rust
fn source(self: &Self) -> Option<ItemsSource>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L231)

<a id="function-set_source"></a>

### set_source

```rust
fn set_source(self: &Self, value: Option<ItemsSource>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L235)

<a id="function-single_select"></a>

### single_select

```rust
fn single_select(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L242)

<a id="function-set_single_select"></a>

### set_single_select

```rust
fn set_single_select(self: &Self, value: bool)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L246)

<a id="function-selected_index"></a>

### selected_index

```rust
fn selected_index(self: &Self) -> i32
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L267)

<a id="function-set_selected_index"></a>

### set_selected_index

```rust
fn set_selected_index(self: &Self, value: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L271)

<a id="function-selected_indexes"></a>

### selected_indexes

```rust
fn selected_indexes(self: &Self) -> Rc<dyn IReadOnlySelectionList<i32>>
```

The selected indexes: a view of the selection, always the same list.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L289)

<a id="function-selected_item"></a>

### selected_item

```rust
fn selected_item(self: &Self) -> Option<T>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L296)

<a id="function-set_selected_item"></a>

### set_selected_item

```rust
fn set_selected_item(self: &Self, value: Option<T>)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L312)

<a id="function-selected_items"></a>

### selected_items

```rust
fn selected_items(self: &Self) -> Rc<dyn IReadOnlySelectionList<Option<T>>>
```

The selected items: a view of the selection. Before a source is
assigned, the items selected by item.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L323)

<a id="function-anchor_index"></a>

### anchor_index

```rust
fn anchor_index(self: &Self) -> i32
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L335)

<a id="function-set_anchor_index"></a>

### set_anchor_index

```rust
fn set_anchor_index(self: &Self, value: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L339)

<a id="function-count"></a>

### count

```rust
fn count(self: &Self) -> usize
```

The number of selected items.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L347)

<a id="function-indexes_changed"></a>

### indexes_changed

```rust
fn indexes_changed(self: &Self, handler: impl Fn(&SelectionModelIndexesChangedEventArgs) -> () + 'static) -> Subscription
```

Subscribes to the event raised when a change to the source shifts
the indexes of selected items.

Dropping the returned guard removes the handler;
`Subscription::detach` keeps it for the life of the model.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L364)

<a id="function-selection_changed"></a>

### selection_changed

```rust
fn selection_changed(self: &Self, handler: impl Fn(&SelectionModelSelectionChangedEventArgsOf<T>) -> () + 'static) -> Subscription
```

Subscribes to the event raised when the selection changes.

Dropping the returned guard removes the handler;
`Subscription::detach` keeps it for the life of the model.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L378)

<a id="function-lost_selection"></a>

### lost_selection

```rust
fn lost_selection(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
```

Subscribes to the event raised when the selection becomes empty.

Dropping the returned guard removes the handler;
`Subscription::detach` keeps it for the life of the model.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L392)

<a id="function-source_reset"></a>

### source_reset

```rust
fn source_reset(self: &Self, handler: impl Fn() -> () + 'static) -> Subscription
```

Subscribes to the event raised when the source is reset.

Dropping the returned guard removes the handler;
`Subscription::detach` keeps it for the life of the model.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L403)

<a id="function-batch_update"></a>

### batch_update

```rust
fn batch_update(self: &Self) -> BatchUpdateOperation
```

Begins a batch update that ends when the returned operation is
disposed or dropped.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L421)

<a id="function-begin_batch_update"></a>

### begin_batch_update

```rust
fn begin_batch_update(self: &Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L425)

<a id="function-end_batch_update"></a>

### end_batch_update

```rust
fn end_batch_update(self: &Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L432)

<a id="function-is_selected"></a>

### is_selected

```rust
fn is_selected(self: &Self, index: i32) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L449)

<a id="function-select"></a>

### select

```rust
fn select(self: &Self, index: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L459)

<a id="function-deselect"></a>

### deselect

```rust
fn deselect(self: &Self, index: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L463)

<a id="function-select_range"></a>

### select_range

```rust
fn select_range(self: &Self, start: i32, end: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L467)

<a id="function-deselect_range"></a>

### deselect_range

```rust
fn deselect_range(self: &Self, start: i32, end: i32)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L471)

<a id="function-select_all"></a>

### select_all

```rust
fn select_all(self: &Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L503)

<a id="function-clear"></a>

### clear

```rust
fn clear(self: &Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L517)

<a id="function-raise_property_changed"></a>

### raise_property_changed

```rust
fn raise_property_changed(self: &Self, property_name: &str)
```

Raises the property changed event.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L522)

<a id="function-base_set_source"></a>

### base_set_source

```rust
fn base_set_source(self: &Self, value: Option<ItemsSource>)
```

The implementation of `set_source` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L527)

<a id="function-base_on_indexes_changed"></a>

### base_on_indexes_changed

```rust
fn base_on_indexes_changed(self: &Self, shift_index: i32, shift_delta: i32)
```

The implementation of `on_indexes_changed` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L566)

<a id="function-base_on_source_collection_change_started"></a>

### base_on_source_collection_change_started

```rust
fn base_on_source_collection_change_started(self: &Self)
```

The implementation of `on_source_collection_change_started` of this
type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L578)

<a id="function-base_on_source_reset"></a>

### base_on_source_reset

```rust
fn base_on_source_reset(self: &Self)
```

The implementation of `on_source_reset` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L584)

<a id="function-base_on_selection_removed"></a>

### base_on_selection_removed

```rust
fn base_on_selection_removed(self: &Self, _index: i32, _count: i32, deselected_items: Vec<Option<T>>)
```

The implementation of `on_selection_removed` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L595)

<a id="function-base_on_items_added"></a>

### base_on_items_added

```rust
fn base_on_items_added(self: &Self, index: i32, items: ItemsView<'_>) -> CollectionChangeState<T>
```

The implementation of `on_items_added` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L613)

<a id="function-base_on_items_removed"></a>

### base_on_items_removed

```rust
fn base_on_items_removed(self: &Self, index: i32, items: ItemsView<'_>) -> CollectionChangeState<T>
```

The implementation of `on_items_removed` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L628)

<a id="function-base_on_source_collection_changed"></a>

### base_on_source_collection_changed

```rust
fn base_on_source_collection_changed(self: &Self, e: &ItemsChangedEventArgs<'_>)
```

The implementation of `on_source_collection_changed` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L663)

<a id="function-base_is_valid_collection_change"></a>

### base_is_valid_collection_change

```rust
fn base_is_valid_collection_change(self: &Self, e: &ItemsChangedEventArgs<'_>) -> bool
```

The implementation of `is_valid_collection_change` of this type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L701)

<a id="function-base_on_source_collection_change_finished"></a>

### base_on_source_collection_change_finished

```rust
fn base_on_source_collection_change_finished(self: &Self)
```

The implementation of `on_source_collection_change_finished` of this
type.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/selection/selection_model.rs#L725)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`
- [`SelectionNodeBaseImpl<T>`](/docs/0.5.0/api/ferroui-controls/selection/trait-selectionnodebaseimpl/)
- [`INotifyPropertyChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifypropertychanged/)
- [`ISelectionModel`](/docs/0.5.0/api/ferroui-controls/selection/trait-iselectionmodel/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
