How can I capture the keystroke that triggers “CellEndEdit” on a DataGridView in C#?

Set the KeyPrevew property on your form to true; that will prevent the control from gobbling it up first. :).

Thanks, but after trying this, it looks like the escape key is still only being recognized by the cell as the end of the edit and not as an actual KeyDown or KeyPress event on the form. – Andy Stampor Apr 22 '09 at 14:01.

First, you're absolutely right, KeyPreview won't work. At first, I thought I could get around this by overriding the IsInputKey method of the form. This technique has worked for me in some other cases where I couldn't catch a key I needed to catch.

That didn't work either, so I tried subclassing the DataGridView and overriding IsInputKey there. That didn't work either. After some digging through the other methods I could override, I learned there was another class of keys called command keys that I needed to intercept.To do that, override ProcessCmdKey on your DataGridView (you'll need to subclass it).

Here is my code: public class CommandKeyInterceptingDataGridView : DataGridView { protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { Debug. WriteLine(keyData); return base. ProcessCmdKey(ref msg, keyData); } } And the output from entering edit mode with F2, modifying a cell to say "" and canceling the edit with Escape.

F2 ShiftKey, Shift H, Shift E L L O Escape Hopefully this gives you what you need.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions