I have a DataGridView and a handler for the EditingControlShowing event which is used to add or remove handlers for the keyUp event for some columns. The problem is sometimes a column which does not have an associated KeyUp handler actually fires the handler. It seems like the grid does not know which column is supposed to fire which handler.
Problem: When I type in column2 (not column1), the line which removes the KeyUp handler runs.. so far so good. But then the Control_KeyUp runs! Control_KeyUp is only for Column1.
Is there a way to find out if a column (or cell?) has handlers attached to it?
private void MyGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
string columnName = MyGrid.Columns[MyGrid.CurrentCell.ColumnIndex].Name;
if (columnName == "column1")
e.Control.KeyPress += new KeyPressEventHandler(Control_KeyUp);
else
e.Control.KeyPress -= new KeyPressEventHandler(Control_KeyUp);
......
}