
Untitled
By: a guest on
Jun 25th, 2012 | syntax:
None | size: 0.85 KB | hits: 11 | expires: Never
Creating an autocomplete textbox that works on both first name, and last name
private void txtClientName_TextChanged(object sender, EventArgs e)
{
if (txtClientName.Text.Length == 1)
{
completeCollection.Clear();
CustomerRepository repo = new CustomerRepository();
var customers = repo.FindAllCustomers().Where(u => u.Name.StartsWith(txtClientName.Text) || u.LastName.StartsWith(txtClientName.Text));
foreach (var customer in customers)
{
completeCollection.Add(customer.Name + " " + customer.LastName);
}
txtClientName.AutoCompleteMode = AutoCompleteMode.Suggest;
txtClientName.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtClientName.AutoCompleteCustomSource = completeCollection;
}
}
completeCollection.Add(customer.Lastname + ", " + customer.Name);