Blazor Selectbar only works for enumerables

Hi,

First of all, kudos on this free library of blazor components.
I was trying to use the Radzen SelectBar (https://blazor.radzen.com/selectbar), but following the example that is posted on the demo website, I keep getting an error.

The control does not seem to work as on the example.
I tryed this very simple usage:

<RadzenSelectBar @bind-Value="clientType" TValue="string">
	<Items>
		<RadzenSelectBarItem Text="Private" Value="Private" />
		<RadzenSelectBarItem Text="Enterprise" Value="Enterprise" />
	</Items>
</RadzenSelectBar>

@code {
    string clientType = "Private";
}

but I get several errors from that code snipet:

  • error CS1503: Argument 1: cannot convert from 'string' to 'System.Collections.Generic.IEnumerable'
  • error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback' to 'Microsoft.AspNetCore.Components.EventCallback'
  • error CS0029: Cannot implicitly convert type 'string' to 'System.Collections.Generic.IEnumerable'
  • error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
  • error CS0103: The name 'Private' does not exist in the current context
  • error CS0103: The name 'Enterprise' does not exist in the current context

First thing that called my attention was the error about binding against a variable that is not an ienumerable (if i change "clientType" to a IEnumerable<string> this error goes away).
Then the Values of the RadzenSelectBarItem are also indicating that I cannot use strings?
It works if I change them to numbers or if I create variables with a string value and bind them in the RadzenSelectBarItem, but that does not seem to make much sense to me.

Am I doing something wrong on my part?
Thanks

HI @andre.sousa,

The demo shows how to use RadzenSelectBar with both single and multiple values. The first component in the demo is bound to single int value:

<RadzenSelectBar @bind-Value="value" TValue="int">
  <Items>
    <RadzenSelectBarItem Text="Orders" Value="1" />
    <RadzenSelectBarItem Text="Employees" Value="2" />
    <RadzenSelectBarItem Text="Customers" Value="3" />
  </Items>
</RadzenSelectBar>
...
@code {
    int value = 2
    ...
}

The second is bound to multiple values:

<RadzenSelectBar @bind-Value="values" TValue="IEnumerable<int>" Multiple="true">
  <Items>
    <RadzenSelectBarItem Text="Orders" Value="1" />
    <RadzenSelectBarItem Text="Employees" Value="2" />
    <RadzenSelectBarItem Text="Customers" Value="3" />
  </Items>
</RadzenSelectBar>
...
@code {
    IEnumerable<int> values = new int[] { 1, 2 };
    ...
}

Thanks Enchev, but that was my point exactly.
The example with the binding of single values was not working.

But I found out what is going on. I was still using v2.9.0
This feature does not seem to exist in that version. It does not even compile
As of v2.9.2 it works as expected.

Thanks.

@andre.sousa Upgrading to latest package fixed it for me too.

@enchev Does RazdenSelectBar support IEnumerable of string?


Types is IEnumerable of string and running code as above results in a runtime exception "Cannot convert Int32 to string".

In image below, VS is complaining that variables with names Internal, Shipping and Transfer are not found.

What I ended up doing to bind with string values is assign the value to a variable and the use the variable in the value of the SelectBarItem.

Try it out.
Don't have an explanation for it though.
Just got there by trial and error.

I think you can also do it if you define the value like this

Value="@("Internal")"

Thanks. It worked for me.