void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox txtbox = e.Control as TextBox;
if (this.dataGridView1.CurrentCell.ColumnIndex == 0)
{
if (txtbox != null)
{
//
}
}
}
我还编写了AutoCompleteStringCollection。
代码正在运行,
在编辑列1之前,它将不允许任何其他列的自动完成
一旦编辑了列1,所有列将与列1工作相同。
请帮助我如何解决问题或其他任何最好的方法,请在这里分享。
应该可以。
private bool firstColEdited = false;
/************************************************************/
var source = new AutoCompleteStringCollection();
String[] stringArray = Array.ConvertAll<DataRow, String>(products.Select(), delegate(DataRow row) { return (String)row["code"]; });
source.AddRange(stringArray);
/************************************************************/
void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
TextBox txtbox = e.Control as TextBox;
if (this.dataGridView1.CurrentCell.ColumnIndex == 0 || firstColEdited)
{
firstColEdited = true;
txtbox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
txtbox.AutoCompleteCustomSource = source;
txtbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
}
}