Can I make DataGridView.EndEdit trigger the CellValidating event?

Posted by Don Kirkby on Stack Overflow See other posts from Stack Overflow or by Don Kirkby
Published on 2009-01-08T01:16:13Z Indexed on 2010/04/05 8:23 UTC
Read the original article Hit count: 275

Filed under:
|
|

I'm using a DataGridView in my WinForms application. My main objective is to make the Enter key not move to the next row in the grid. I still want the enter key to validate and end edit mode.

I found this FAQ entry and subclassed DataGridView to override ProcessDialogKey(). If the key pressed is Enter, I call EndEdit(), otherwise I call base.ProcessDialogKey().

It works great, except the CellValidating event isn't fired.

Currently, I'm just manually calling my validation logic before I call EndEdit, but it seems like I'm missing something.

I guess I could call OnCellValidating, but then I'd be worried I'm missing some other event. What I really want is some flavour of EndEdit() that behaves just like pressing enter on the last row of a grid with adding disabled.

© Stack Overflow or respective owner

Related posts about winforms

Related posts about c#