我内部有一个DataGridView
和两个ComboBox
列。在从第一个ComboBox控件中选择值时,我应该在第二个ComboBox中绑定数据。但是当我从第二个ComboBox中选择一个项目时,相同的事件会被多次激活。
我使用以下代码:
void Grid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
var cell = e.Control as ComboBox;
if (cell != null)
{
cell.SelectedIndexChanged -= doWork;
cell.SelectedIndexChanged += doWork;
}
}
public void doWork(object sender, EventArgs e)
{
string str="";
var tb = datagrdADDTEMP.EditingControl as ComboBox;
if (tb.SelectedValue != null)
{
str = tb.SelectedValue.ToString();
}
}