我有 ComboBox 控件(WinForm 项目)。
当我将 DataSource 绑定(bind)到 ComboBox 控件时,触发了 combobox_selectedindexchanged 事件。
知道如何在绑定(bind) DataSource 时防止 selectedindexchanged 事件吗?
最佳答案
删除 SelectedIndex_Changed 事件的处理程序,绑定(bind)您的数据,然后重新添加处理程序。以下是如何在方法中完成此操作的简单示例:
private void LoadYourComboBox()
{
this.comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged);
// Set your bindings here . . .
this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
}
关于c# - 绑定(bind)DataSource时如何防止selectedindexchanged事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14111879/