在我的DatagridView
中,我有两列,ComboxboxColumn
和TextboxColumn
。我想更改文本框的值
当组合框选择了索引更改时(通常组合框中它选择了索引更改事件,但datagridviewComboBox
没有它)
答案 0 :(得分:4)
给出这两个简单的方法(top方法中的'1'是组合框列的索引)
您可以修改的行是设置行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();
}