RadAutoCompleteBox

3 posts, 1 answers
  1. Amos
    Amos avatar
    6 posts
    Member since:
    Jul 2014

    Posted 25 Jun 2015 Link to this post

    Hi,

    Is there any way to allow RadAutoCompleteBox auto suggestion item to select only unique items. For example, RadAutoCompleteBox has item A, item B and item C. I don't want user to choose Item A two times. Would like to remove previously selected item from auto suggestion list. For example Item A is already in the RadAutoCompleteBox.Items collection, want to show only item B and C in auto complete suggestion box. If not possible to do that, want to cancel the selection if existing item is selected again. Is it possible to do that?

     

  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 29 Jun 2015 Link to this post

    Hello Amos,

    Thank you for writing.

    You can achieve your requirement by setting the RadAutoCompleteBox.ListElement.DataLayer.DataView.Filter predicate. Thus, you can control whether a specific RadListDataItem will be displayed in the popup or not. Here is a sample implementation:
    public Form1()
    {
        InitializeComponent();
     
        List<Item> items = new List<Item>();
        items.Add(new Item(1,"A1"));
        items.Add(new Item(2,"A2"));
        items.Add(new Item(3,"A3"));
        this.radAutoCompleteBox1.AutoCompleteDataSource = items;
        this.radAutoCompleteBox1.AutoCompleteDisplayMember = "Name";
        this.radAutoCompleteBox1.AutoCompleteValueMember = "Id";
     
        this.radAutoCompleteBox1.ListElement.DataLayer.DataView.Filter = FilterItem;
    }
     
    private bool FilterItem(RadListDataItem item)
    {
        string[] tokens = this.radAutoCompleteBox1.Text.Split(new char[] { ';' },
            StringSplitOptions.RemoveEmptyEntries);
        if (tokens.Length > 0)
        {
            foreach (string token in tokens)
            {
                if (item.Text.StartsWith(token))
                {
                    return false;
                }
            }
        }
     
        return true;
    }
     
    public class Item
    {
        public int Id { get; set; }
     
        public string Name { get; set; }
     
        public Item(int id, string name)
        {
            this.Id = id;
            this.Name = name;
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Dess
    Telerik

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Amos
    Amos avatar
    6 posts
    Member since:
    Jul 2014

    Posted 30 Jun 2015 in reply to Dess Link to this post

    Thanks you. It helps me.

    Regards

Back to Top