我有一个带有 2 个组合框列的数据网格。我为组合框列编写了选择更改事件,如下所示。
private void Grid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb!=null)
{ cb.SelectionChangeCommitted -= new EventHandler(cb_SelectedIndexChanged);
// now attach the event handler
cb.SelectionChangeCommitted += new EventHandler(cb_SelectedIndexChanged);
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
var tb = datagrdADDTEMP.EditingControl as ComboBox;
if (tb != null)
str = tb.SelectedValue != null ? tb.SelectedValue.ToString() : null;
Assesment_Business_layer.Businesslayer bl = new Assesment_Business_layer.Businesslayer();
DataSet ds = new DataSet();**strong text**
ds = bl.GetSubCatNamesBA(str);
cmbDataGridSubCategory.DataSource = ds.Tables[0];
cmbDataGridSubCategory.DisplayMember = "SubCategoryName";
cmbDataGridSubCategory.ValueMember = "SubCategoryCode";
}
}
它与第一个组合框列配合良好,但问题是当我从第二个组合框列中选择项目时,上述选择更改事件也会引发..但我不想为第二个组合列引发选择更改事件。它应该只为第一个组合框加注。
请帮忙,因为我遇到了这个问题。