Select programatically

hi,

I have a lot of different chipgroups and I can't manage with selected items to select programmatically.

Then I created a custom chip group and customized for my needs.

But I can't manage to have the selectedmemberpath to work (in the underlined color).

To explain I want exactly the same as TextMemberPath but for the selection. I want to specify the selected path which will set selected or not.

CheckMemberPath is a bindable prop I created.


How can I do it?

thanks,

  private void Child_ChildAdded(object sender, ElementEventArgs e)
        {
            var sfChip = e.Element as SfChip;
            if (sfChip != null)
            {
                    sfChip.ShowSelectionIndicator = ShowIndicator;
                

                sfChip.SetBinding(SfChip.CornerRadiusProperty, new Binding() { Path = "CornerRadius", Source = this, Mode = BindingMode.TwoWay });

                if (ImageIsUrl)
                {
                    string value = (sfChip.ImageSource as FileImageSource).File;
                    sfChip.ImageSource = new UrlImageConverter().Convert(value, typeof(SfChip), null, null) as ImageSource;
                   
                }

                sfChip.Text= new TranslateConverter().Convert(sfChip.Text, typeof(SfChip),null, null) as string;

                sfChip.SetBinding(SfChip.IsCheckedProperty, new Binding() { Path = CheckMemberPath, Mode = BindingMode.TwoWay });
            }
        }

5 Replies 1 reply marked as answer

AL Alexis February 25, 2021 10:17 AM UTC

Hi,

It's too complicated because I will have a lot of different chipgroups to manage.

It's not possible to create a bindable property for checkmemberpath and setup it in my custom chip group?

As you can see I try to reproduce this.

Then I have Category, interest.

I have a sflistview which fills the list of categories of interests. And then interest list is automatically binded on sfchipgroup.

Then I would like when I come back to the page to check the previous interests checked.

And the easiest will be to bind the sfchip to the checked property when it's added to my custom sfchipgroup.

Possible to do it?

 




SM Saravanan Madheswaran Syncfusion Team February 25, 2021 10:18 AM UTC

Hi Alexis, 
 
From the update, we can understand that you are trying to maintain the selected chip items after clearing or reload the list view items. So, we would like to suggest binding selected items from view model property. 
 
Please check the below code and modified sample.  
 
public class Book : INotifyPropertyChanged 
              private List<Word> selectedItems = new List<Word>(); 
              public List<Word> SelectedItems 
             
 
                             get { return selectedItems; } 
                             set 
                             
                                           selectedItems = value; 
                                           PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedItems")); 
                            
 
             
 
At Xaml: 
<SyncfusionButtons:SfChipGroup Margin="0,10"  
                               x:Name="cg"  
                               ItemsSource="{Binding Words}" SelectedItems="{Binding SelectedItems}" DisplayMemberPath="Name"> 
. . . 
. . . 
 
 
Image after second selection. 
 
 
Please let us know if we misunderstood your application use case.  
 
Regards, 
Saravanan.  


Marked as answer

JL Janet Locane July 16, 2021 09:26 AM UTC

Very good explanation. Thank you.



JL Janet Locane July 16, 2021 09:28 AM UTC

I have been looking for this information for a very long time. And nobody could help me. Now I know what to do.



YP Yuvaraj Palanisamy Syncfusion Team July 19, 2021 04:31 AM UTC

Hi Janet Locane, 

Thank you for your update. 

We are glad to that the solution working fine at your end. 

Regards, 
Yuvaraj. 


Loader.
Up arrow icon