This is the output:
First, this is the setup for my autocomplete:
//The tags for autocompletebox on XAML
Second, my simple snippets:
//Event for the autocomplete to send a text string to my function
private void autoCompleteBox1_KeyUp(object sender, KeyEventArgs e)
{
autoCompleteBox1.Populating += (s, args) =>
{
args.Cancel = true;
var c = new Service1Client();
c.GetListByNameCompleted +=new EventHandler
c.GetListByNameAsync(autoCompleteBox1.Text);
};
}
//Getting result from database
void c_GetListByNameCompleted(object sender, GetListByNameCompletedEventArgs e)
{
autoCompleteBox1.ItemsSource = e.Result;
autoCompleteBox1.PopulateComplete();
}
The snippets above will show on how to use the autocompleteBox using the data from database that bind in DataGrid. But what if we want to show the result on DataGrid while the autocomplete changing the items source?
Ok just add one line to c_GetListByNameCompleted
void c_GetListByNameCompleted(object sender, GetListByNameCompletedEventArgs e)
{
autoCompleteBox1.ItemsSource = e.Result;
autoCompleteBox1.PopulateComplete();
dataGrid1.ItemsSource = e.Result;
}