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

How to Programatically add items to autocompletebox

I'm currently using the autocompletebox with multiselect. 

My current code

View

               
    autocomplete:SfAutoComplete MultiSelectMode="Token"
                                HorizontalOptions="FillAndExpand"                                                                
                                VerticalOptions="EndAndExpand"
                                TokensWrapMode="Wrap" 
                                Text="{Binding Keyword, Mode=TwoWay }"
                                IsSelectedItemsVisibleInDropDown="false"
                                Watermark="Add..."
                                HeightRequest="120"
                                SelectedItem="{Binding SelectedKeywords, Mode=TwoWay}"
                                DataSource="{Binding Keywords}">
     autocomplete:SfAutoComplete>
       
   

ViewModel


    public ObservableCollection Keywords
    {
        get { return _keywords; }
        set { _keywords = value; OnPropertyChanged("Keywords"); }
    }

    public ObservableCollectionSelectedKeywords
    {
        get { return _selectedKeywords; }
        set { _selectedKeywords = value; OnPropertyChanged("SelectedKeywords"); }
    }

    Keywords = new ObservableCollection() { "Apples" , "Bananas" ,  "Celery" } ;

The issue I'm coming across is that when tokens are selected on the app (if I were to select apple), SelectedKeywords is not updated, the count will remain zero. BUT if I were to change it to be of ObservableCollection<object><object> it works perfect.

The next issue I'm coming across is clearing SelectedKeywords<object>. I would like to also do the reverse, adding items to the SelectedKeywords, but the UI isn't reflected. 

Any assistance would be greatly appreciated. 




1 Reply

SK Selva Kumar  Veerakrishnan Syncfusion Team February 20, 2019 03:39 AM UTC

Hi Minh, 

 
Greetings from Syncfusion. 

 
Query 1: When selecting the items in Token mode, selected item count is not updated correctly. 

 
We have created the SfAutoComplete sample in which we have updated the selected item count when the selection gets changed inside SelectionChanged event and the selected item counts updated correctly in Token mode. We have prepared the sample for your reference. Please download it from the below link. 

 
Query 2: After clearing the selected item and adding the selected item dynamically UI does not reflected. 

 
We have tried your requirement by clearing the existing item in the autocomplete and we have tried adding the selected item collection dynamically. The selected item updated in UI in android and in iOS we are facing the exception. We have provided the sample below. Please download it from the below link. 

 
Please try our sample and let us know you are facing the same issue in iOS. If not please modify the given sample and provide us with more details on which scenario you could reproduce the issue and it will help us work further with your requirement 

 
Regards, 
Selvakumar V 


Loader.
Live Chat Icon For mobile
Up arrow icon