2012-06-30 51 views
2

在我的DatagridView中,我有兩列,ComboxboxColumnTextboxColumn。我想改變文本框 當組合框選擇索引更改的值(通常組合框中它已選擇索引更改事件,但datagridviewComboBox不具備它)DatagridviewComboBox選擇索引更改時更改DatagridviewTextBox文本

+0

這是WPF中,的WinForms,Silverlight的,別的東西嗎? –

+0

對不起,它的winforms,我現在標記 – Arash

回答

4

給這兩個簡單的方法一個去(頂部'1'方法是組合框列的索引)

您要修改的行將是setter行cel.Value =,因爲您可以將其更改爲任何您喜歡的行。


private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) 
    { 
     if (dataGridView1.CurrentCell.ColumnIndex == 1 && e.Control is ComboBox) 
     { 
      ComboBox comboBox = e.Control as ComboBox; 
      comboBox.SelectedIndexChanged += LastColumnComboSelectionChanged; 
     } 
    } 

    private void LastColumnComboSelectionChanged(object sender, EventArgs e) 
    { 
     var currentcell = dataGridView1.CurrentCellAddress; 
     var sendingCB = sender as DataGridViewComboBoxEditingControl; 
     DataGridViewTextBoxCell cel = (DataGridViewTextBoxCell)dataGridView1.Rows[currentcell.Y].Cells[0]; 
     cel.Value = sendingCB.EditingControlFormattedValue.ToString(); 
    } 

enter image description here

+1

我希望我能得分這更多!它幫了我很多。 – Derek