DropDown Multiple with integer value

Hello,

In the demo of dropdown with multiple selection the ValueProperty CustomerID is a string.

I'm trying to set similar example, but in my case, the property I'm using as ValueProperty is an integer.
For the @bind-value, if I assign an IEnumerable<string> it will thrown a invalid cast operation. If I assign a IEnumerable<int> it doesn't thrown any exception, but I can't select (check) any value.

Is there a limitation in this feature that only works with String values?

<RadzenDropDown Name="Workspace" Multiple="true" Data="@(workspaces.Where(x => x.BuildingId == BuildingId))" TextProperty="Name" ValueProperty="WorkspaceId" @bind-Value="@selectedWorkspaceIds" Placeholder="Select..." Class="w100p" />

IEnumerable<int> selectedWorkspaceIds;

 public class Workspace
    {
        public int WorkspaceId { get; set; }
        public string Name { get; set; }
        public int BuildingId { get; set; }
}

No, there is no such limitation. The following seems to work as expected:

<RadzenDropDown Name="Workspace" Multiple="true"
   Data="@(workspaces)" TextProperty="Name" ValueProperty="WorkspaceId"
   @bind- Value="@selectedWorkspaceIds" 
   Placeholder="Select..." Class="w100p" 
/>

@code {
    IEnumerable<int> selectedWorkspaceIds;

    public class Workspace
    {
        public int WorkspaceId { get; set; }
        public string Name { get; set; }
        public int BuildingId { get; set; }
    }

    IEnumerable<Workspace> workspaces = new [] { 
        new Workspace { WorkspaceId = 1, Name = "WS 1"},
        new Workspace { WorkspaceId = 2, Name = "WS 2"}
    };
}

dropdown

Hi @korchev,

Thank you for you prompt reply and confirmation.
I refactored my code and somehow it works as expected. It's hard to say what was going in the way of the dropdown events.

Thanks again

Hello @korchev

Just now I noticed that combining Cascading DropDowns with Multiple selection does not work.

In your example, you set Data="@(workspaces)" , while I am actually using Data="@(workspaces.Where(x => x.BuildingId == BuildingId))" because the list of "workspaces" needs to be refreshed if the user selects another "building" in the previous dropdown.

I still worked out my way by setting Data="@(workspaces)" in the "workspaces" dropdown and setting a method at the Change event callback in the "buildings" dropdown to update the list of workspaces.

Is this something that can be improved in a future release of the components?

Thanks!

What doesn't work? We are not aware of such problem.

Hey @korchev
Sorry for my lack of explanation.

In my tests, when having a cascading dropdown and the second (child) dropdown is of type "multi selection", I can't select any option. The options are listed, but the checkboxes never become "checked".

Could you give it a try if you have time?

<RadzenDropDown 
    Name="Building"
    Data="@buildings"
    TextProperty="Name"
    ValueProperty="BuildingId"
    @bind-Value="@BuildingId"
 />

<RadzenDropDown
     Name="Workspace"
     Multiple="true"
     Data="@(workspaces.Where(x => x.BuildingId == BuildingId))"
     TextProperty="Name"
     ValueProperty="WorkspaceId"
    @bind-Value="@selectedWorkspaceIds"
/>


@code {
    [Parameter]
    public int BuildingId { get; set; }

    IEnumerable<int> selectedWorkspaceIds;
    IEnumerable<Building> buildings;
    IEnumerable<Workspace> workspaces;

    protected override async Task OnInitializedAsync()
    {
        buildings = dbContext.Buildings;
        workspaces = dbContext.Workspaces;

       // call for an authentication-related async method
    }
}

public class Building
{
    public int BuildingId { get; set; }
    public string Name { get; set; }
    public ICollection<Workspace> Workspaces { get; set; }
}

public class Workspace
{
    public int WorkspaceId { get; set; }
    public string Name { get; set; }
    public int BuildingId { get; set; }
    public Building Building { get; set; }
    public ICollection<Reservation> Reservations { get; set; }
}

Check here for an explanation why multiple selection does not work when Data is set as an expression.