DxListBox<TData, TValue>.SelectedDataItemsChanged Event
Fires when selection changes.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v25.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public EventCallback<SelectedDataItemsChangedEventArgs<TData>> SelectedDataItemsChanged { get; set; }
Event Data
The SelectedDataItemsChanged event's data class is SelectedDataItemsChangedEventArgs<TData>. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| ChangeSource | Identifies an action that causes selection change. Inherited from SelectionChangedEventArgs. |
| DataItems | Returns a collection of currently selected items. |
Remarks
Handle the SelectedDataItemsChanged event to respond to item selection changes. This event fires in the following cases:
- When users change item selection.
- When Value and Values properties are changed at runtime or in code. This also refers to the first render.
The SelectedDataItemsChanged event allows you to use the following argument properties in a handler:
- ChangeSource to identify an action that causes selection change.
- DataItems to obtain information about the selected items.
<DxButton Click="SelectAll" Text="Select All Items" />
<DxButton Click="DeselectAll" Text="Deselect All Items" />
<DxListBox Data="@Staff.DataSource"
@ref=_listBox
ValueFieldName="@nameof(Person.Id)"
TextFieldName="@nameof(Person.Text)"
SelectionMode="ListBoxSelectionMode.Multiple"
ShowCheckboxes="true"
ShowSelectAllCheckbox="true"
@bind-Values="@Values"
SelectedDataItemsChanged="(SelectedDataItemsChangedEventArgs<Person> args) =>
OnSelectedDataItemsChanged(args)" />
<p>@msg</p>
@code {
string msg;
DxListBox<Person, int> _listBox;
IEnumerable<int> Values { get; set; } = Staff.DataSource.Take(3).Select(t => t.Id);
void OnSelectedDataItemsChanged(SelectedDataItemsChangedEventArgs<Person> args) {
var selected = args.DataItems?.ToList() ?? new List<Person>();
var sourceText = args.ChangeSource switch {
SelectionChangeSource.ParameterChange => "Selection is set/changed in code.",
SelectionChangeSource.ApiCall => "Selection is changed by an API call.",
_ => "Selection is changed by a user action."
};
msg = selected.Count == 0
? $"{sourceText} No items selected."
: $"{sourceText} Selected ({selected.Count}): " +
string.Join(", ", selected.Select(p => $"{p.FirstName} {p.LastName}"));
}
async Task SelectAll(MouseEventArgs args) {
await MyListBox.SelectAllAsync();
}
async Task DeselectAll(MouseEventArgs args) {
await MyListBox.DeselectAllAsync();
}
}
See Also