I have a combobox which will have search for items after 3rd letter is entered. I'm assigning itemssource after I enter 3rd letter.
What I need to do is I want to start auto complete as soon as they type 3rd letter(i.e after I assign itemssource).
But as soon as I assigned the itemsource it clears whtever I typed and it's not even let me to type again.
Please let me know if there is a way to do that.
private void radCmbCustomerName_KeyDown(object sender, KeyEventArgs e)
{
if (radCmbCustomerName.Text != null && radCmbCustomerName.Text.Length == 3)
{
SearchCustomerName(radCmbCustomerName.Text.ToLower());
}
}
private
void SearchCustomerName(string name)
{
db =
DBContractEntity.CreateDataServiceInstance();
allCustomers =
new ObservableCollection<sh_customer>();
DataServiceQuery<sh_customer> query = (DataServiceQuery<sh_customer>)db.sh_customer.Where(u => u.name.ToLower().StartsWith(name));
query.BeginExecute(OnAllCustomersComplete, query);
}
private void OnAllCustomersComplete(IAsyncResult result)
{
Dispatcher.BeginInvoke(() =>
{
DataServiceQuery<sh_customer> query = result.AsyncState as DataServiceQuery<sh_customer>;
try
{
Dispatcher.BeginInvoke(
delegate()
{
var returnedAllCustomers = query.EndExecute(result);
if (returnedAllCustomers != null)
{
allCustomers.RemoveAll();
foreach (sh_customer aCustomer in returnedAllCustomers)
{
allCustomers.Add(aCustomer);
}
}
var sortedCustomers = from customers in allCustomers
orderby customers.name ascending
select customers;
string name = radCmbCustomerName.Text;
if (sortedCustomers.Count()>0)
{
radCmbCustomerName.ItemsSource = sortedCustomers.ToList();
}
});
}
catch (DataServiceQueryException ex)
{
addBusyIndicator.IsBusy =
false;
MessageBox.Show(ex.Message);
}
}
);
}