Option for Maximum Number of Selections allowed in multiselect

I am facing an issue where there is no option to limit the maximum number of selections inside the SFAutocomplete controller.

When trying to limit it manually using the SelectionChanged event, i am getting all kinds of wierd behavior such as the selected value coming as an Observable Collection one time and as a Generic List in another trigger. 


Even with accounting for both, the viewmodel is not being updated with the binding and when trying to manually set the view model attribute i am getting a null value from parsing the collection as any type.


1 Reply

AJ AhamedAliNishad JahirHussain Syncfusion Team December 26, 2023 03:21 PM UTC

Hi Ali,


We have reviewed your query, and currently, we don't have a property for setting the maximum number of selections in MultiSelectMode in SfAutoComplete Xamarin Forms. However, we have implemented a workaround by restricting the SelectedItem based on the count within the SelectionChanging event of the SfAutoComplete, as shown in the following code snippet. Additionally, we have attached a sample for your reference. Please review it and let us know the details.


Code Snippet:


Mainpage.xaml

 

        private void autoCompleteProfessions_SelectionChanging(object sender, SelectionChangingEventArgs e)

        {

            var autoComplete = sender as SfAutoComplete;

            var selectedItem = (autoComplete.SelectedItem as ObservableCollection<Object>);

            if (selectedItem.Count >= VM.MaximumSelection)

            {

                e.Cancel = true;

            }

            else

            {

                e.Cancel = false;

            }

        }

 


Regards,

Ahamed Ali Nishad.


Attachment: SfAutoCompleteXa_6a6cc303.zip

Loader.
Up arrow icon