In My DatagridView
,I Have Two Columns, ComboxboxColumn
and TextboxColumn
. I want to change the value of textbox
when combobox selected index changes (in general combobox it has selected index change event but datagridviewComboBox
does not have it)
Asked
Active
Viewed 2,460 times
2
-
Is this WPF, Winforms, Silverlight, something else? – Kevin Aenmey Jun 30 '12 at 21:05
-
sorry its winforms,i tagged that now – Arash Jun 30 '12 at 21:06
1 Answers
4
Give these two simple methods a go (the '1' in the top method is the index of the combobox column)
The line that you would make you modifications to would be the setter line cel.Value =
, as you may change it to whatever you like.
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();
}