![]() |
EditingControlShowing in DataGridView w 2 combobox
Hello fellow programmers,
I have a dataGridView with 2 comboBoxColumns amongst simple textboxColumns. When I click on the combo in column 4 everything is good grid_EditingControlShowing is called and rawComboChanged is called after it. But when i then click on column 11, rawComboChanged is called immediately, skipping the call to grid_EditingControlShowing that should point the code towards currencyChanged method. I think i found the problem: "The DataGridView reuses editing controls across cells if the type is the same"... But i dont have a solution... Can anyone help? public void grid_EditingControlShowing(object sender, System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs e) { DataGridView dataGridView = (DataGridView)sender; ComboBox comboBox = new ComboBox(); if (dataGridView.CurrentCell.ColumnIndex == 4) { comboBox = e.Control as ComboBox; comboBox.SelectedIndexChanged += new System.EventHandler(this.rawComboChanged); } else if (dataGridView.CurrentCell.ColumnIndex == 11) { comboBox = e.Control as ComboBox; comboBox.SelectedIndexChanged += new System.EventHandler(this.currencyChanged); } } Mike |
4 years after...
Hi, I'm facing the same problem, and figured out that adding a line that substracts the event evertime it enters to the method event-catcher will fix the problem. this is my code:
private void dgConceptos_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { DataGridView dataGridView = (DataGridView)sender; ComboBox comboBox = new ComboBox(); if (dataGridView.CurrentCell.ColumnIndex == 0) { comboBox = e.Control as ComboBox; if (comboBox != null) { comboBox.SelectedIndexChanged -= new EventHandler(dgConceptosComboBoxDescripcion_Select edIndexChanged); comboBox.SelectedIndexChanged += new EventHandler(dgConceptosComboBoxDescripcion_Select edIndexChanged); } } } private void dgConceptosComboBoxDescripcion_SelectedIndexChange d(object sender, EventArgs e) { ComboBox comboBox = (ComboBox)sender; if (!string.IsNullOrEmpty(comboBox.Text)) { some code here... } comboBox.SelectedIndexChanged -= new EventHandler(dgConceptosComboBoxDescripcion_Select edIndexChanged); } |
All times are GMT -4. The time now is 05:53 PM. |
Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.