We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Using Filter type and need to set some chips to be checked programatically

I am using SfChipGroup in order to create a filter in our app. In our app, the user will tap the ones they want and then save. We are grabbing all of the selected chips from SelectedItems and then storing that for future use. That would fine.

What we are not able to do is when the user goes back to the group we want to check the chips that they had selected before. Setting SfChipGroup.Items[x].IsChecked does not seem to do anything.

How can we make this work?

Carl


3 Replies

LA Lavanya Anaimuthu Syncfusion Team June 15, 2019 03:42 PM UTC

Hi Carl, 
 
Thanks for contacting Syncfusion Support. 
 
We glad to achieve your requirement " holding selected items using SelectedItems property". 
 
Query: We want to check the chips they has selected before. 
 
SelectedItems is just to hold only the selected items property. If those selected items are removed from its selection, it also removed from SelectedItems property also. 
 
We understood that you need a collection to holds only the previously selected chips. If that means we can get that from SelectionChanged event like in below 
 
[XAML] MainPage.xaml 
 
  <StackLayout>
            <ScrollView>
                <buttons:SfChipGroup 
                Type="Filter"
                ItemsSource="{Binding ChipItems}"
                SelectionChanged="SfChipGroup_SelectionChanged"
                SelectedItems="{Binding SelectedItems}"
                DisplayMemberPath="Product"/>
            </ScrollView>
            <Label Text="Already selected Chips" Margin="0,10,0,0"/>
            <ListView ItemsSource="{Binding PreviouslySelectedItems}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Label Text="{Binding Product}" />
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
 
 
[C#] MainPage.xaml.cs 
 
  private void SfChipGroup_SelectionChanged(object sender, Syncfusion.Buttons.XForms.SfChip.SelectionChangedEventArgs e)
        {
            if (!viewModel.PreviouslySelectedItems.Contains(e.AddedItem) && e.AddedItem != null)
            {
                viewModel.PreviouslySelectedItems.Add(e.AddedItem as Model);
            }
        }
 
 
PreviouslySelectedItems holds only the selected chips from ChipGroup.  We have prepared a simple sample to achieve your requirement. 
 
 
If we misunderstood query, please update us with more details to check further and provide a better solution. 
 
Regards, 
Lavanya A. 



BC Blaise Coco June 15, 2019 04:56 PM UTC

Thanks. That will work fine for me. 


MK Muneesh Kumar G Syncfusion Team June 17, 2019 05:52 AM UTC

Hi Carl,  
 
Thanks for the update. 
  
We are glad to know that the given solution works. Please let us know if you need any further assistance. 
 
Thanks, 
Muneesh Kumar G. 


Loader.
Live Chat Icon For mobile
Up arrow icon