How can I validate input to the edit control of a cell in a DataGridView?

20 May
<code>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);

Referenced by:

Leave a comment

Posted by on May 20, 2011 in C#, Window Application


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: