AutoCompleteBox when empty entries
-
20-06-2021 - |
题
I am using this filter in my AutoCompeteBox.
bool SearchBird(string search, object value)
{
if (value != null)
{
AllBirds datasourceValue = value as AllBirds;
string name = datasourceValue.primary_language;
if (name.ToLower().StartsWith(search.ToLower()))
return true;
}
// If no match, return false.
return false;
}
Everything is working well when all entries have some value, but when there is any empty record it's crushing giving an error with null exception (which is understandable as there is no value). Tried do smth with extra if or else statement but still getting the same error.
解决方案
more better if u use if else?
add this after if, may be help
else {
return false;
}
其他提示
I've done that like that.
if (value != null)
{
AllBirds datasourceValue = value as AllBirds;
string name = datasourceValue.primary_language;
if (name == null)
return false;
if (name.ToLower().StartsWith(search.ToLower()))
return true;
}
// If no match, return false.
return false;
不隶属于 StackOverflow