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

How to set RadAutoCompleteView's tokens programmatically?

4 Answers 87 Views
AutoCompleteView
This is a migrated thread and some comments may be shown as answers.
Mehdi
Top achievements
Rank 1
Veteran
Mehdi asked on 13 Aug 2020, 08:43 PM

Hi, I have just begun using RadAutoCompleteView, and now I am looking for a way to set its selected items (tokens) in code-behind when I am going to open my entity's detail page in edition mode.

 

P.s. I am not using MVVM architecture and setting my control's ItemsSource programmatically:

Class:
public class Activity

    public string Id { get; set; }
    public List<string> ProductIds { get; set; }
}

ItemsSource: SomeListOfProducts.

 

What I'm going to do:

For each productId in ProductIds, I add a token to my RadAutoCompleteView that: token = SomeListOfProducts.Single(x => x.Id == productId).

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 14 Aug 2020, 12:20 PM

Hi Mehdi,

You can use the RadAutoCompleteView Tokens collection and add the token directly to it:

foreach (int i in this.ProductIds)
{
    this.autoCompleteView.Tokens.Add(products.Single(p => p.ProductId == i));
} 

I have attached a quick example to show you how this works.

Please download the attachment and give it a try. Let me know if any additional questions pop up.

Regards,
Yana
Progress Telerik

0
Mehdi
Top achievements
Rank 1
Veteran
answered on 14 Aug 2020, 07:14 PM

Hi Yana,

Thanx a lot for the guidance. Actually I thought the 'Tokens' property is read-only. However, I couldn't find any attachments.

Best regards,

Mehdi

0
Yana
Telerik team
answered on 17 Aug 2020, 05:16 AM

Hi Mehdi,

I am sorry for the missing example - you can find it attached to this thread.

Tokens collection is indeed read-only, meaning you cannot initialize, it, still, you can add and remove items from it.

Regards,
Yana
Progress Telerik

0
Mehdi
Top achievements
Rank 1
Veteran
answered on 17 Aug 2020, 06:46 AM

Hi Yana,

Thanx a lot.

Best regards,
Mehdi

Tags
AutoCompleteView
Asked by
Mehdi
Top achievements
Rank 1
Veteran
Answers by
Yana
Telerik team
Mehdi
Top achievements
Rank 1
Veteran
Share this question
or