This is a migrated thread and some comments may be shown as answers.

Limit Selected Items in RadAutoCompleteBox

3 Answers 226 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Veeraguru
Top achievements
Rank 1
Veeraguru asked on 03 Mar 2017, 01:35 PM

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. 

 

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 08 Mar 2017, 09:40 AM
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.
0
Veeraguru
Top achievements
Rank 1
answered on 09 Mar 2017, 09:21 AM

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.

 

 

 

 

0
Stefan
Telerik team
answered on 14 Mar 2017, 08:17 AM
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.
Tags
General Discussions
Asked by
Veeraguru
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Veeraguru
Top achievements
Rank 1
Share this question
or