Multiple Selection ListBox and SelectedItem

Hello fellow Radzen users/fans!

I can't seem to get the @bind-SelectedItem of the RadzenListBox to work when Multiple="true". My RadzenListBox is as follows:

<RadzenListBox Style="height:700px;width:100%;"
	Data="@contacts" TextProperty="DisplayName"
	TValue="IEnumerable<ContactDto>" @bind-Value="selectedContacts" Change="@(args => Change(args))"
	AllowFiltering="true" AllowClear="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
	Multiple="true" @bind-SelectedItem="selectedContact">
</RadzenListBox>

The multiple selection is working just fine. I can get the list of the selected items.

But I'm also trying to bind the selected item (to 'selectedContact') to display other properties of the selected item elsewhere. The 'selectedContact' is currently an object type because I believe the RadzenListBox is expecting an object, but ideally, I would like it to be of ContactDto type. When I tried to cast, I get exception.

I also tried the below but it doesn't seem to get the last selected item in the list (which would give me the recently selected item):

        var selectedContactsList = selectedContacts.ToList();

        StateHasChanged();
        contact = selectedContactsList.LastOrDefault();

Also, is there a way to check/uncheck the checkbox only by directly clicking on the checkbox of the item instead of merely by the act of selecting the item? This is a bit annoying and I do not know how to work around this.

Thank you ahead for the help.

Hi @radzenkenn,

Please use Value to bind to selected items/values similar to our example:
https://blazor.radzen.com/listbox

Hi enchev:

Thank you for providing assistance.

As stated, I do not have any problems getting the selected items/values. This is working just fine.

The issue I have is when I attempt to bind the most recently clicked on item by the user, this is where my various attempts at using the @bind-SelectedItem and other methods failed.

Does the RadzenListBox track the most recently selected/clicked on item by the user?

Also, the other issue is there is no way to turn off the automatic checking/unchecking of an item whenever the user merely selects it? Is there a workaround or future implementation that will correct this behaviour?

Regards,
kenn

Additional clarification of use case. . . ..

I would like to use the RadzenListBox as follows:

  • Allows the user to check items that he/she wants to actually do something with (example: generate a report for the checked items).
  • Allows the user to view other properties of the item by clicking on (selecting) the item without the automatic checking/unchecking of the item. The user can then determine whether to check/uncheck the item (by directly clicking on the checkbox) based on properties of the clicked on/selected item.

Hope this explains it a bit better.

Regards,
kenn