I have DataGridView
with two columns. The first column is TextBoxCol(DataGridViewTextBoxColumn)
and the Second one is ComboBoxCol(DataGridViewComboBoxColumn)
.
How can I change the value of TextBoxCol
when ComboBoxCol
changes its selected index value?
(This should happen when selected index changed in ComboBoxCol
. Not after leaving the column, like dataGridView_CellValueChanged
)
I have read one topic with almost the same problem that I am having but I dont understand the answer(which should be correct base on the check mark). Here's the link. -Almost same topic
This answer is floating around in a couple of places. Using the DataGridViewEditingControlShowingEventHandler will fire more events than you intend. In my testing it fired the event multiple times. Also using the combo.SelectedIndexChanged -= event will not really remove the event, they just keep stacking. Anyway, I found a solution that seems to work. I'm including a code sample below:
That link is correct. Handle the
EditingControlShowing event
of DataGridView. In this event handler, check if the current column is of your interest. And, then create a temporary combobox object :-ComboBox comboBox = e.Control as ComboBox;
MSDN has a sample: See in the example section here. Note the
Inheritance Hierarchy
&Class Syntax
in the msdn link : -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.