DatagridView Multiple ComboBox issue
-
I have attached the following code. I have a datagridview with three comboboxes on it. When I select an item from the first combobox it functions as intended. The problem I am having is that when I click on the second or third combobox it executes the item_SelectedIndexChanged event as shown below. I know I am missing something stupid! Any help is appreciated! Thanks! private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { int columnindex = dataGridView1.CurrentCell.ColumnIndex; ComboBox combo; if (dataGridView1.CurrentCell.ColumnIndex == 3) { combo = e.Control as ComboBox; if (combo == null) return; combo.SelectedIndexChanged -= item_SelectedIndexChanged; combo.SelectedIndexChanged += item_SelectedIndexChanged; } } void item_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmbBox = (ComboBox)sender; int x = Convert.ToInt32(cmbBox.SelectedIndex.ToString()); int y = dataGridView1.CurrentRow.Index; dataGridView1.Rows[y].Cells[4].Value = dsInvoice.Parts.Rows[x]["DESC"].ToString(); dataGridView1.Rows[y].Cells[5].Value = Convert.ToDecimal(dsInvoice.Parts.Rows[x]["Price"].ToString()); }
-
I have attached the following code. I have a datagridview with three comboboxes on it. When I select an item from the first combobox it functions as intended. The problem I am having is that when I click on the second or third combobox it executes the item_SelectedIndexChanged event as shown below. I know I am missing something stupid! Any help is appreciated! Thanks! private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { int columnindex = dataGridView1.CurrentCell.ColumnIndex; ComboBox combo; if (dataGridView1.CurrentCell.ColumnIndex == 3) { combo = e.Control as ComboBox; if (combo == null) return; combo.SelectedIndexChanged -= item_SelectedIndexChanged; combo.SelectedIndexChanged += item_SelectedIndexChanged; } } void item_SelectedIndexChanged(object sender, EventArgs e) { ComboBox cmbBox = (ComboBox)sender; int x = Convert.ToInt32(cmbBox.SelectedIndex.ToString()); int y = dataGridView1.CurrentRow.Index; dataGridView1.Rows[y].Cells[4].Value = dsInvoice.Parts.Rows[x]["DESC"].ToString(); dataGridView1.Rows[y].Cells[5].Value = Convert.ToDecimal(dsInvoice.Parts.Rows[x]["Price"].ToString()); }
kruegersck wrote:
The problem I am having is that when I click on the second or third combobox it executes the item_SelectedIndexChanged event as shown below.
I'm not sure what you mean. Is the problem that it is supposed to execute that routine and does something you don't want, or that you want it to execute something else? If you want it to do something else, we need to know what you are trying to do. If you don't want it to execute that routine, then remove it from the events or use a different routine.
CQ de W5ALT
Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software