我有一个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();
}
}