How to avoid adding duplicate tokens to Tokens collection

Environment

Product Version 2019.1.318.1
Product AutoCompleteView for Xamarin

Description

What is the best way to avoid adding duplicate tokens to Tokens collection RadAutoCompleteView?

Solution

You could use SuggestionItemSelected event to remove the item - this event is fired before the item is actually added to the Tokens collection, so, if you call directly in its handler the Remove method of the Tokens collection, it will remove the second time the item is added. Here is a sample snippet:

<telerikInput:RadAutoCompleteView x:Name="autoCompleteView"
            ImagePath="ImageSource"
            ItemsSource="{Binding Source}"
            TextSearchPath="Name"
            DisplayMode="Tokens"                               
            SuggestionItemSelected="AutoCompleteView_SuggestionItemSelected"/>

and the event handler:

private void AutoCompleteView_SuggestionItemSelected(object sender, Telerik.XamarinForms.Input.AutoComplete.SuggestionItemSelectedEventArgs e)
{
    autoCompleteView.Tokens.Remove(e.DataItem);
}
In this article
Not finding the help you need? Improve this article