I have a problem with binding multiple values from ListBox.
When I change selection invalid cast exception is thrown as shown on image below
Both ParameterValuesList and SelectedParameterValues are List.
What am I doing wrong?
I have a problem with binding multiple values from ListBox.
When I change selection invalid cast exception is thrown as shown on image below
Both ParameterValuesList and SelectedParameterValues are List.
What am I doing wrong?
What type is the item of the list?
List item is class with three properties:
public long? Id { get; set; }
public int? KindId { get; set; }
public string DisplayName { get; set; }
so I wanted to have list of selected items in SelecetedParematerValues.
In winforms project this kind of binding is possible and I am not sure if it is possible in Blazor with ListBox. If not, is there any alternative?
If DropDown ValueProperty is not set you will get selected items as IEnumerable<YourClass>
, if ValueProperty is set (for example to Id) you will get selected items as IEnumerable<long?>
.
Thank you for your quick replies.
In example on picture in my first post ValueProperty is not set and exception is thrown only when I click checkbox to select or unselect items.
Binding through code looks to work fine. On start, items from SelecetedParematerValues list are checked fine. I have also added two test buttons. One that adds one item to selection and other that removes all selections and everything works as expected.
public void TestAddBinding()
{
CurrentUsedParameter.SelectedParameterValues.Add(CurrentUsedParameter.ParameterValues.First());
}
public void TestRemoveBinding()
{
CurrentUsedParameter.SelectedParameterValues.Clear();
}
What could be a reason so checkbox change is throwing invalid cast exception?
I cannot tell from provided info why you get the exception. If you have Radzen license you can send us the project at info@radzen.com to debug it.