I have the following code which only works when looking up the first 3 characters at the start of the line. However, I want to be able to show AutoComplete data by searching anywhere in the line.
private void txtCMDestination_TextChanged(object sender, EventArgs e)
{
try
{
TextBox t = sender as TextBox;
if (t != null)
{
if (t.Text.Length >= 3)
{
var arr = IndexItems.Where(x => x.ToUpper().Contains(t.Text.ToUpper())).ToArray();
var collection = new AutoCompleteStringCollection();
collection.AddRange(arr);
txtCMDestination.AutoCompleteCustomSource = collection;
}
}
}
catch (Exception) { }
}
Does anyone know what I am doing wrong here?
Cheers.
EDIT
I have debugged to ensure that var arr
contains filtered data when I type in the 3 chars and it does. So my LINQ is working as expected, which leads to me to believe there is something wrong with txtCMDestination.AutoCompleteCustomSource = collection;
receiving the collection?