DataGrid - event after changing selection

How can I trigger an event after a selection change? I need to walk through the selected items and display a quick preview of the information after changing the selection.

I see that the DataGrid has a RowSelect and RowDeselect event, but if I take the DataGrid / Multiselection sample code, then at the time the RowSelect and RowDeselect functions are called, the selectedEmployees variable does not yet contain the currently selected/deselected item.


<RadzenDataGrid AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowPaging="true" PageSize="4"
                AllowSorting="true" Data="@employees" TItem="Employee" ColumnWidth="200px"
                SelectionMode="DataGridSelectionMode.Multiple" @bind-Value=@selectedEmployees>
            <RadzenDataGridColumn TItem="Employee" Width="40px" Sortable="false" Filterable="false">
                    <RadzenCheckBox TriState="false" TValue="bool" Value="@(employees.Any(i => selectedEmployees != null && selectedEmployees.Contains(i)))"
                                    Change="@(args => selectedEmployees = args ? employees.ToList() : null)" />
                <Template Context="data">
                    <RadzenCheckBox TriState="false" Value="@(selectedEmployees != null && selectedEmployees.Contains(data))" />
            <RadzenDataGridColumn TItem="Employee" Property="EmployeeID" Title="Employee ID" />
            <RadzenDataGridColumn TItem="Employee" Property="Photo" Title="Employee" Sortable="false" Filterable="false">
                <Template Context="data">
                    <RadzenImage Path="@data.Photo" style="width: 40px; height: 40px; border-radius: 8px;" />
                    @data.FirstName @data.LastName
            <RadzenDataGridColumn TItem="Employee" Property="Title" Title="Title" />
            <RadzenDataGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" FormatString="{0:d}" />
            <RadzenDataGridColumn TItem="Employee" Property="City" Title="City" />
            <RadzenDataGridColumn TItem="Employee" Property="Country" Title="Country" />

Hi @Artur_Dash,

You can just use the selectedEmployees field - Blazor will refresh the markup when it changes. Alternatively you can use a property and add your code in the setter.

1 Like

Thanks for the tip with the property. I hadn't thought of that! Works great :slight_smile: