views:

489

answers:

2

I have a control with an undo feature, when the user press Escape the control will revert the original value.

The problem is when I integrated my control to DataGridView. The DataGridView "eats" the Escape key, hence my control cannot detect the Escape key.

When I put "return true" on EditingControlWantsInputKey, my control was able to detect the Escape key, but other problem arised, the DataGridView cannot close my control, it stays in EditMode.

How to allow my control to detect the Escape key while also allowing the DataGridView to close my control?

A: 

You should "return true" only when Keys.KeyCode == Keys.Escape;
otherwise return !dataGridViewWantsInputKey.

I tried that, but it didn't work. It is my control then that eats the key, hence DataGridView cannot close my control.
Michael Buen
A: 

I was able to solved my own problem. I made the Undo method of my LookupBox public, then on my DataGridView control (class DgvLookupBoxEditingControl : LookupBox, IDataGridViewEditingControl), I put the following code:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        if (keyData == Keys.Escape)            
            this.Undo();            

        return base.ProcessCmdKey(ref msg, keyData);


    }
Michael Buen