Get all selected value using multi selection mode

Hello,

I am using a SfAutocomplete in multi selection mode.

the data source is a List<lot>

How do a get my selected lot ?

I tried  SfAutoComplete.SelectedItem but it's return an object, and I didn't manage to cast this object to List<lot>

Can you help me on this ? 

And also, I will need after to select all this lot by code, this will work ? 

sfautocomplete.SelectedItem = List<lot> 

Thanks !

4 Replies 1 reply marked as answer

SS Suganya Sethuraman Syncfusion Team June 1, 2021 08:54 AM UTC

Hi Nexti,

Greetings from Syncfusion.

We have analyzed your requirement. As shown in the code snippet below, we can get the datatype of SelectedItem in SfAutoComplete is ObservableCollectionobject> in the SelectionChanged event.

Code snippet 
 
        private void autoComplete_SelectionChanged(object sender, Syncfusion.SfAutoComplete.XForms.SelectionChangedEventArgs e)  
        {  
            SfAutoComplete autoComplete = sender as SfAutoComplete;  
            if (autoComplete.SelectedItem is ObservableCollection<object>)  
            {  
                var selectedItems = autoComplete.SelectedItem as ObservableCollection<object>;  
            }  
        }  

Please have a sample for your reference,

Sample:  https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoCompleteSample-1636059275

Please check if the sample satisfies your requirement and let us know if you have any concerns.

Regards,
Suganya Sethuraman. 
 
 


Marked as answer

NE Nexti June 1, 2021 09:30 AM UTC

Thanks it's working great !

Casting autoCompleteLot.SelectedItem as ObservableCollection<object> help me to loop thought the items insides !


NE Nexti June 1, 2021 10:02 AM UTC

Second question, 

If now, I have my List<class>, and I want, in C#, to select in the SfAutoComplete ? 

Example, I have 5 customers in my autocomplete, and a List of 3 customers that need to be selected at runtime, how do I do that ? 

Setting selectItem = List will work ? 

Thanks 


SS Suganya Sethuraman Syncfusion Team June 2, 2021 07:05 AM UTC

Hi Nexti,

Thanks for your update.

We have analyzed your requirement. We have achieved your requirement by using the SelectedItem property, which is a ListEmployee> datatype in the ViewModel class, and binding it to the SelectedItem API of SfAutoComplete.

Please have a sample for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoCompleteSample1365703689

Please check if the sample satisfies your requirement and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon