如果我正确地理解了您的问题,您希望根据
编辑控件的类型
. 如果是这样,我会这样做:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
//Remove any KeyPress events already attached
e.Control.KeyPress -= new KeyPressEventHandler(FirstEditingControl_KeyPress);
e.Control.KeyPress -= new KeyPressEventHandler(SecondEditingControl_KeyPress);
//Choose event to wire based on control type
if (e.Control is NumericTextBox)
{
e.Control.KeyPress += new KeyPressEventHandler(FirstEditingControl_KeyPress);
} else if (e.Control is CurrencyTextBox)
{
e.Control.KeyPress += new KeyPressEventHandler(SecondEditingControl_KeyPress);
}
}
我从经验中学到了在DataGridView中编辑控件时可能发生的任何事件,因为它们会对多个单元格重用同一个控件。