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

Posted by Stuart Helwig on Stack Overflow See other posts from Stack Overflow or by Stuart Helwig
Published on 2010-04-16T06:41:36Z Indexed on 2010/04/16 7:23 UTC
Read the original article Hit count: 203

Filed under:
|
|

It appears that the only way to capture the keypress events within a cell of a DataGridView control, in order to validate user input as they type, is to us the DataGridView controls OnEditControlShowing event, hook up a method to the edit control's (e.Control) keypress event and do some validation.

My problem is that I've built a heap of custom DataGridView column classes, with their own custom cell types. These cells have their own custom edit controls (things like DateTimePickers, and Numeric or Currency textboxes.)

I want to do some numeric validation for those cells that have Numeric of Currency Textboxes as their edit controls but not all the other cell types.

How can I determine, within the DataGridView's "OnEditControlShowing" override, whether or not a particular edit control needs some numeric validation?

© Stack Overflow or respective owner

Related posts about datagridview

Related posts about .NET