2
在我的DatagridView
中,我有兩列,ComboxboxColumn
和TextboxColumn
。我想改變文本框 當組合框選擇索引更改的值(通常組合框中它已選擇索引更改事件,但datagridviewComboBox
不具備它)DatagridviewComboBox選擇索引更改時更改DatagridviewTextBox文本
在我的DatagridView
中,我有兩列,ComboxboxColumn
和TextboxColumn
。我想改變文本框 當組合框選擇索引更改的值(通常組合框中它已選擇索引更改事件,但datagridviewComboBox
不具備它)DatagridviewComboBox選擇索引更改時更改DatagridviewTextBox文本
給這兩個簡單的方法一個去(頂部'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();
}
我希望我能得分這更多!它幫了我很多。 – Derek
這是WPF中,的WinForms,Silverlight的,別的東西嗎? –
對不起,它的winforms,我現在標記 – Arash