Domanda

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.

È stato utile?

Soluzione

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;
    }
 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top