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

Bind AutoCompleteBox to a List<string>

2 Answers 236 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Herald
Top achievements
Rank 1
Veteran
Iron
Herald asked on 05 Oct 2020, 04:34 PM

Hello

How would I bind the AutoCompleteBox to a simple List<string> or to a string array. Documentation only shows how to bind to a custom object. 

 

Thanks

2 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 08 Oct 2020, 09:33 AM

Hi Herald,

Thank you for your interest in our RadAutoCompleteBox control.

You can use the following code snippet as an example of how to bind the control to a List of strings.

public class MyViewModel
{
    public List<string> Data { get; set; }
    public MyViewModel()
    {
        Data = new List<string>() { "string", "get", "MyViewModel" };
    }
}

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        this.DataContext = new MyViewModel();
    }
}

<Grid>
    <telerik:RadAutoCompleteBox ItemsSource="{Binding Data}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="200"/>        
</Grid>

When you run the project and type "str," the control will autocomplete it by showing the "string" element inside its drop-down content. I hope I was able to help you. Give it a try and let me know how it goes on your side.

Regards,
Dinko
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).

0
Herald
Top achievements
Rank 1
Veteran
Iron
answered on 08 Oct 2020, 04:18 PM

Great. This worked perfectly.

Thanks

Tags
AutoCompleteBox
Asked by
Herald
Top achievements
Rank 1
Veteran
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Herald
Top achievements
Rank 1
Veteran
Iron
Share this question
or