I am trying to get AutoComplete to filter match all three columns of my data.
I had the simple match working, but only on the initial column. My data has three properties: Customer Id, Customer Name and ZipCode. I would like to have it match on any of the three columns.
In the xaml I have a single line:
I call LoadCustomerData in the code-behind constructor.
private async void LoadCustomerData()
{
customerAutoComplete.DataSource = await GetCustomerCodes();
customerAutoComplete.DisplayMemberPath = "CUSTNMBR";
customerAutoComplete.SelectedValuePath = "CUSTNMBR";
customerAutoComplete.SuggestionMode = SuggestionMode.Custom;
customerAutoComplete.Filter = FilterCustomers;
customerAutoComplete.AutoCompleteMode = AutoCompleteMode.Suggest;
customerAutoComplete.Watermark = "Zip Code, Customer ID, or Customer Name";
customerAutoComplete.MinimumPrefixCharacters = 3;
}
My filter function:
private bool FilterCustomers(string search, object customer)
{
var text = customerAutoComplete.Text;
if (customer != null)
{
var myCustomer = (OrganizationSearchDto)customer;
if (myCustomer.CustName.Contains(text) || myCustomer.CustNmbr.Contains(text) ||
myCustomer.Zip.Contains(text))
{
return true;
}
}
return false;
}
I am not using a ViewModel like in the documentation examples. I hope that is not my problem. Also, in the custom filter examples we set AutoCompleteSource and I am still using DataSource.
Baring those two issues, why is my AutoComplete dropdown blank or empty?
I found my error:
public bool ContainingSpaceFilter(string search, object item)
{
if (item != null)
{
var myCustomer = item as Employee;
if (myCustomer.Name.ToUpper().Contains(search.ToUpper()) || myCustomer.ID.Contains(search) ||
myCustomer.ZipCode.Contains(search))
{
return true;
}
}
return false;
} |