2013-05-05 67 views
0
void dataGridView1_EditingControlShowing(object sender,DataGridViewEditingControlShowingEventArgs e) 
{ 

    if (dataGridView1.CurrentCell.ColumnIndex == 1) 
    { 
     TextBox txt= e.Control as TextBox; 

     if (dataGridView1.Columns[1].HeaderText.Equals("Header")) 
     { 
      if (txt!= null) 
      { 
       txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend; 
       txt.AutoCompleteCustomSource = ..datasource...; 
       txt.AutoCompleteSource = AutoCompleteSource.CustomSource; 
      } 
     } 
    } 
} 

當我在第一列開始編輯時,它工作正常。我有更多的一個datagridtextbox列,所以自動完成工作在所有列。我想阻止這種情況,並且必須在dataGridView1.CurrentCell.ColumnIndex == 1中進行綁定。如何將文本框分配給datagridview中的特定列?

+0

你的問題是有點混亂。您是否嘗試爲所有DataGridTextBox列設置自動完成模式,或僅設置第一列? – Tim 2013-05-05 02:32:45

回答

0

我認爲你應該使用這樣的事情

var text = dataGridView1.Columns[1].HeaderText; 
       TextBox txt = new TextBox(); 
       txt.Text = text; 
相關問題