How can I get the edit control in a cell of a DataGridView to validate itself?
- by Stuart Helwig
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?
(In the meantime I've restorted to setting the Tag property of my custom edit controls to a known value and any Edit Controls I find in the OnEditControlShowing override, I hook to my validation routine - I don't like that much!)