DataGrid Multi-Select Add to Selected Items in Code

Consider the following data grid definition:
<RadzenDataGrid @ref="grdData" AllowRowSelectOnRowClick="true" Data="@gridItems" SelectionMode="DataGridSelectionMode.Multiple" @bind-Value=@selectedItems>

    <Columns>
        <Template Context="data">
            <RadzenCheckBox TabIndex="-1" TriState="false" Value="@(selectedItems != null && selectedItems.Contains(data))" TValue="bool" />
        </Template>
        ... other columns
    </Columns>
</RadzenDataGrid>

selectedItems is an IList

I need to add to selectedItems in code and have the grid recognize it (i.e. have the checkbox checked).

Is this possible?

You can assign new value to selectedItems and since this is two-way bound using @bind-Value the DataGrid will respect it.

I had a feeling you might say that, but that is not my experience. I add to the selectedItems list, call StateHasChanged();, and the list does not change. Checking the page afterwards, the selectedItems list does NOT contain the newly added items.

I should add that I am adding to the list during the Change event on the checkbox that determines selection. Is it possible that I'm modifying the list prior to the grid taking control and adding/removing the recently checked item? If so, is there another event that would allow me to manipulate the list.

This is not how Blazor bindings works - you need to replace the value of the entire variable.

Oh, wow. Ok, I'll give that a shot. Thanks.