当用户更改我的网格中 DataGridViewComboBoxColumn 的值时,我需要执行一个操作。假设我必须显示一条消息。
问题是 messagebox.show("hello") 代码执行了数百万次。
这是我的代码。
grilla.EditingControlShowing+=new DataGridViewEditingControlShowingEventHandler(grilla_EditingControlShowing);
void grilla_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is ComboBox) //i have only one combobox column.
{
ComboBox cb = (ComboBox)e.Control;
// first remove event handler to keep from attaching multiple:
cb.SelectedIndexChanged -= new EventHandler(cb_SelectedIndexChanged);
// now attach the event handler
cb.SelectedIndexChanged += new EventHandler(cb_SelectedIndexChanged);
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("hello");
}