Limit Selected Items in RadAutoCompleteBox

4 posts, 0 answers
  1. Veeraguru
    Veeraguru avatar
    11 posts
    Member since:
    Jul 2013

    Posted 03 Mar Link to this post

    Hi Team,

    I have binded Countries list in ItemSource property. How to restrict the selection after some number.

    Eg: India,China,Pakistan,Bangladesh,Japan,Iran --> ItemSource

    User can select only three in these countries. 

     

  2. Stefan X1
    Admin
    Stefan X1 avatar
    751 posts

    Posted 08 Mar Link to this post

    Hello Veeraguru,

    There are two possible solutions that I can suggest you to satisfy such requirement.

    The first one would be to utilize the MaxDropDownHeight property of the control. You can take a look at the Key Properties topic for further reference.

    The other suggestion consists of simply defining a second collection that contains only the needed items from the original source collection and bind the ItemsSource of the control to it. Note, that with such an approach, you will have to manually synchronize the two collections when needed.

    I hope this helps.

    Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Veeraguru
    Veeraguru avatar
    11 posts
    Member since:
    Jul 2013

    Posted 09 Mar in reply to Stefan X1 Link to this post

    First one :

    MaxDropDownHeight - we are just restricting the height.

    Second one :

    I am not sure this will help me.

    ****************************************************************

    Again I am explaining my scenario.

    I have countries list which is binding to the RadAutoCompleteBox.

    User can select any country but maximum 5 (for example).

    How to restrict the user to select the 6th country.

     

     

     

     

  4. Stefan X1
    Admin
    Stefan X1 avatar
    751 posts

    Posted 14 Mar Link to this post

    Hi Veeraguru,

    Thanks for the clarification.

    It seems that I have misunderstood you initially. Please, excuse me for that.

    Unfortunately, the control does not provide an out-of-the-box mechanism for disabling its selection. A possible workaround would be to subscribe to the SelectionChanged event of the control, cast the SelectedItems to IList and remove the needed item. Please, check the following code snippet as an example.
    private void RadAutoCompleteBox_SelectionChanged(object sender,
        SelectionChangedEventArgs e)
    {
        var source = (this.autoComplete.ItemsSource as ObservableCollection<Club>);
        var list = this.autoComplete.SelectedItems as IList;
         
        if (e.AddedItems[0] == source.ElementAt(0))
        {
            list.Remove(e.AddedItems[0]);
        }
    }

    Hopefully, this helps.

    Best Regards,
    Stefan X1
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top