Question

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.

Était-ce utile?

La solution

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;
    }
 }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top