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;
}
Hi dude,
ReplyDeleteCan i have code for it?
johnrajst@gmail.com
Very useful!
ReplyDeleteThank you very much!
Hi Sai,
ReplyDeleteThank you for your snippet, it helps a lot, but i have 1 doubt,
what is the Service1Client in line --
var c = new Service1Client();
is it a dataServiceClient().