I have this error specified cast is not valid while trying to do autocomplete for datagridviewtextboxcell.. I have attached a snapshot of the code along with the stack trace. Am i missing something here??
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox prodCode = e.Control as TextBox;
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
var source = new AutoCompleteStringCollection();
String[] stringArray = newDB.CustomerTbls.Where(s => s.Status == "Active" & s.Type == "Customer").Select(s => s.Name).ToArray<string>();
source.AddRange(stringArray);
if (prodCode != null)
{
prodCode.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
prodCode.AutoCompleteCustomSource = source;
prodCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}
else
prodCode.AutoCompleteCustomSource = null;
}


I figured out the issue myself. The form in which i was trying to do
Datagridview Autocompletewas aChild Form. And the code which I posted above was working in anew Form. So i opened theChild Formas a newThreadand tried running the code and it worked!! Thanx for all your help @chridam.