How do I get the list of items from code behind

Say if my users selects Mon,Tue,Wed how do i get that comma sep list of choices from the code behind in c#


I ideally a want to use the

      <syncfusion:SfChipGroup ChildAdded="daySelection_ChildAdded" ChipClicked="daySelection_ChipClicked" SelectionChanged="daySelection_SelectionChanged" x:Name="daySelection" Type="Filter" SelectionIndicatorColor="Black" SelectedChipTextColor="Blue" ChipBackgroundColor="Black" ChipTextColor="White" Visual="Material">

                <syncfusion:SfChipGroup.Items>

                    <syncfusion:SfChip Text="Sun"/>

                    <syncfusion:SfChip Text="Mon"/>

                    <syncfusion:SfChip Text="Tue"/>

                    <syncfusion:SfChip Text="Wed"/>

                    <syncfusion:SfChip Text="Thu"/>

                    <syncfusion:SfChip Text="Fri"/>

                </syncfusion:SfChipGroup.Items>

            </syncfusion:SfChipGroup>


private void daySelection_SelectionChanged(object sender, Syncfusion.Buttons.XForms.SfChip.SelectionChangedEventArgs e)

{



}

But am finding it hard to understand how to loop through the items


3 Replies

GM Gayathri Manickam Syncfusion Team January 12, 2022 03:55 PM UTC

Hi David,  
  
We have achieved your requirement “show the selected items separated by comma in ChipGroup” with help of SelectedItems property as shown in the below code snippet.  
  
C#  
private void daySelection_SelectionChanged(object sender, Syncfusion.Buttons.XForms.SfChip.SelectionChangedEventArgs e) 
       
            var selectedItems = (sender as SfChipGroup).SelectedItems; 
            if(selectedItems != null
           
                if (selectedItems.Count == 0) 
                    label.Text = ""
 
                for (int i = 0; i < selectedItems.Count; i++) 
               
                    if (i == 0) 
                   
                        label.Text = (selectedItems[i] as SfChip).Text; 
                   
                    else 
                        label.Text += "," + (selectedItems[i] as SfChip).Text; 
               
            }                 
       
  
Please download the sample in the below link and let us know if you have any other queries.  
 
Thanks, 
Gayathri M. 



DA David January 12, 2022 04:02 PM UTC

Thats the magic sauce i was missing


    (sender as SfChipGroup).SelectedItems; 



GM Gayathri Manickam Syncfusion Team January 13, 2022 08:46 AM UTC

Hi David, 
 
We glad that the provided solution works at your end. Please let us know if you need any further assistance. 
 
Regards,  
Gayathri M 


Loader.
Up arrow icon