我specified cast is not valid
在尝试autocomplete
为datagridviewtextboxcell
.. 执行此操作时遇到此错误。我附上了代码的快照以及stack trace
. 我在这里错过了什么吗?
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;
}