1
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.

arun
  • 29
  • 1
  • 6
  • You must explain the second point. – Incredible Apr 15 '13 at 12:22
  • Hi, Thanks for your reply. Actually i want to add textbox with AutoCompleteStringCollection in 'First column' only. So i tried here this.dataGridView1.CurrentCell.ColumnIndex == 0. But it is working for all columns with same behavior. Help me.. – arun Apr 16 '13 at 16:02

1 Answers1

1

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;
    }
 }
Glimpse
  • 462
  • 2
  • 8
  • 25