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

How do I set an item in an AutoCompleteBox

1 Answer 322 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Zac
Top achievements
Rank 1
Zac asked on 14 Sep 2015, 06:51 PM

I use an AutoCompleteBox in conjunction with a List<T> returned from a WCF service that uses Linq to retrieve suggested items based on a number of criteria. I only allow the selection of one complete token item whose value ultimately gets entered into a database table. This works as expected. My question is on the flip side, when I load an entity, I want to take the value that was written into the database and create the token setting the value and text properties and set it.

 I tried the Items property, but that is read-only. Cant find anything obvious in the documentation either.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Sep 2015, 10:03 AM
Hello Zac,

Thank you for writing.

If I understand your requirement correctly, you are trying to set a specific item as a token in RadAutoCompleteBox. For this purpose, it is necessary to set the RadAutoCompleteBox.Text property to the AutoCompleteDisplayMember property of the desired item concatenated with the delimiter. Here is a sample code snippet:
public Form1()
{
    InitializeComponent();
    List<Item> items = new List<Item>();
    for (int i = 0; i < 10; i++)
    {
        items.Add(new Item(i,"Item" + i));
    }
    this.radAutoCompleteBox1.AutoCompleteDataSource = items;
    this.radAutoCompleteBox1.AutoCompleteDisplayMember = "Name";
    this.radAutoCompleteBox1.AutoCompleteValueMember = "Id";
 
    this.radAutoCompleteBox1.Text = items[3].Name+ this.radAutoCompleteBox1.Delimiter;
 
}
 
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;
    }
}

If it is not the desired behavior, please give us some more details about the exact result that you are trying to achieve. Thus, we would be able to think about a suitable solution.

I hope this information helps. Should you have further questions I would be glad to help.
 
Regards,
Dess
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Zac
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or