Since you've updated your question, I understand your question better. You've also said the underlying data and function aren't pertinent, which makes it difficult to understand exactly what you're trying to achieve, so my recommendation would be to create a custom ComboBox
and see if you can handle the matching on your own.
I think the most elegant way to write a function to test whether the typed text is an item in a
ComboBox
would be to use an extension method. Your calls would look like this:
// see if the Text typed in the combobox is in the autocomplete list
bool bFoundAuto = autoCompleteCombo.TextIsAutocompleteItem();
// see if the Text type in the combobox is an item in the items list
bool bFoundItem = autoCompleteCombo.TextIsItem();
The extension methods could be created as follows where you can customize exactly how your search logic is to work. In the two extension methods I wrote below, they simply check to see if the text typed into the ComboBox
is found in the AutoCompleteCustomSource
collection, or, in the second function, if the text is found in the Items
collection.
public static class MyExtensions
{
// returns true if the Text property value is found in the
// AutoCompleteCustomSource collection
public static bool TextIsAutocompleteItem(this ComboBox cb)
{
return cb.AutoCompleteCustomSource.OfType<string>()
.Where(a => a.ToLower() == cb.Text.ToLower()).Any();
}
// returns true of the Text property value is found in the Items col
public static bool TextIsItem(this ComboBox cb)
{
return cb.Items.OfType<string>()
.Where(a => a.ToLower() == cb.Text.ToLower()).Any();
}
}