المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : DatagridView Multiple ComboBox issue



C# Programming
03-15-2010, 04:24 AM
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());
}