How to get all selected items in a list box

Hello, im unable to get all all/ single selected items in the list. Any help will be appreciated.

<SfListBox  TValue="List<Team>"  DataSource="@projectTeams" TItem="Team">
                <ListBoxEvents ValueChange="@onChange" TValue="List<Team>"/>
                <ListBoxFieldSettings Text="TeamName" Value="Team"/>
                <ListBoxSelectionSettings ShowCheckbox="true" ShowSelectAll="true"></ListBoxSelectionSettings>
                <Syncfusion.Blazor.Lists.ListViewEvents TValue="Team"Selected="@OnSelection"></Syncfusion.Blazor.Lists.ListViewEvents>
            </SfListBox>


Object:
public class Team
    {
        public int Id { get; set; }
      public string TeamName { get; set; }
        public string Description { get; set; }
          public string Role { get; set; }
        public bool isPrivate { get; set; } = false;
        public DateTime TimeCreated { get; set; } = DateTime.Now;
        public int ProjectId { get; set; }
        public Project Project { get; set; }
        public List<TeamMember> TeamMembers { get; set; } = new List<TeamMember>();
}

Currently im doing this:

public void onChange(ListBoxChangeEventArgs args)
    {
        Console.WriteLine("onChange");

        //var cd = ((Newtonsoft.Json.Linq.JArray)args.Value).ToObject<List<Team>>()[0];

        Newtonsoft.Json.Linq.JArray cd = args.Items as Newtonsoft.Json.Linq.JArray;

        if (cd != null)
        {
            Console.WriteLine(cd.GetType());

            var abc = cd.ToObject<List<Team>>();

            Console.WriteLine(abc[0]);
        }

    }

Any help will be appreciated.

12 Replies

MK Mohan Kumar Ramasamy Syncfusion Team September 1, 2020 06:40 AM UTC

Hi Dodzi, 
 
We have checked your reported query, we can get the order of selected items using Value property. Please refer below code snippets. 
 
<div class="col-lg-12 control-section"> 
    <div id="listbox-control"> 
        <h4>Select your favorite car:</h4> 
        <SfListBox DataSource="@Data" TValue="string[]" TItem="DataValues" @bind-Value="@Value"></SfListBox> 
 
        <br /> <br /> 
        <h4> Selected Items </h4> 
        <br />  
        @{ 
 
            foreach (string item in Value) 
            { 
                <div> @item </div> 
            } 
 
        } 
    </div> 
</div> 
 
@code{ 
    public string[] Value = new string[] { "Hennessey Venom" }; 
} 
 
For your reference we have prepared a sample. Please find the sample link. 
 
 
Please let us know if you need any further assistance, 
 
Regards, 
Mohankumar R 
 



DO Dodzi September 1, 2020 07:12 AM UTC

Thanks for the quick response. This works, however, is there a way I can get the selected objects and not the property in the object?

Regards


DO Dodzi September 1, 2020 03:07 PM UTC

Just want to say that this works really well. Thanks alot.


MK Mohan Kumar Ramasamy Syncfusion Team September 2, 2020 08:47 AM UTC

Hi Dodzi,   
  
Thanks for the update.  
 
We are happy to hear that your requirement has been fulfilled. Please feel free to contact us if you need any further assistance on this. 
 
Regards, 
Mohankumar R 



ML Michael Lambert October 6, 2020 02:03 AM UTC

Is there anyway to get the whole selected object(s) and just not the Value(s)?


MK Mohan Kumar Ramasamy Syncfusion Team October 6, 2020 05:19 AM UTC

Hi Michael, 
 
We have checked your reported query, we can achieve your requirement using GetDataByValue. Please refer the below code snippets. 
 
 
@using Syncfusion.Blazor.DropDowns 
 
 <SfListBox @ref="ListBoxObj" DataSource="@Vehicles" TValue="string[]" TItem="VehicleData" @bind-Value="@Value"> 
        <ListBoxFieldSettings Text="Text" Value="Text" /> 
    </SfListBox> 
 
<button @onclick="Created">Click</button> 
 
@code{ 
    public string[] Value = new string[] { "Hennessey Venom" }; 
    SfListBox<string[], VehicleData> ListBoxObj; 
 
    private void Created() 
    { 
      var Values =  ListBoxObj.GetDataByValue(Value); 
    } 
 
} 
 
 
For your reference, we have prepared a sample based on this, please refer below link. 
 
 
Please let us know, if you need any further assistance. 
 
Regards, 
Mohan kumar R 



DW Dan Wood February 9, 2023 08:55 PM UTC

This should be in the documentation. 



YA YuvanShankar Arunagiri Syncfusion Team February 13, 2023 08:14 AM UTC

Hi Dan,


We will consider your request and update it in our online documentation site. This documentation will be refreshed in end of February.


Regards,

YuvanShankar A



YA YuvanShankar Arunagiri Syncfusion Team March 30, 2023 11:48 AM UTC

Sorry for the delay, Dan.

 

Due to some technical issues, the list box UG documentation didn't refresh for this volume 1 main release. We will refresh the UG documentation for the list box by mid of April 2023. We appreciate your patience until then.



YA YuvanShankar Arunagiri Syncfusion Team April 4, 2023 07:01 AM UTC

Hi Dan,


We have corrected the reported issue in our online UG documentation. Please check the below UG link for reference.


UG link: https://blazor.syncfusion.com/documentation/listbox/how-to/get-items


Please get back to us if you need further assistance.


Regards,

YuvanShankar A



DC David Clough replied to YuvanShankar Arunagiri August 22, 2024 03:40 PM UTC

This blazor.syncfusion.com page can’t be found



KV Keerthikaran Venkatachalam Syncfusion Team August 23, 2024 11:23 AM UTC

Hi David,


The Blazor Syncfusion demo sites are loading properly on our end. Please refer to the video demonstration and the demo link provided below. If you are still facing issues, please provide more details along with a video demonstration. Based on that information, we will check the issue and provide you with a prompt solution.


Demo link: https://blazor.syncfusion.com


Please let us know if you need any further assistance on this.


Regards,

KeerthiKaran K V


Attachment: screencapture_70b3d395.zip

Loader.
Up arrow icon