void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
     TextBox txtbox = e.Control as TextBox;
     if (this.dataGridView1.CurrentCell.ColumnIndex == 0)
     {
         if (txtbox != null)
         {
             //
         }
     }
}

Also I have coded with AutoCompleteStringCollection.

Code is working,

  1. Before edit Column 1, It won't allow autoCompletion for any of other column.

  2. Once edited Column 1, all column will work same as Column one.

Please help me how to fix issue or else any other best way to do that, please share here.

有帮助吗?

解决方案

This should work.

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;
    }
 }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top