Property Grid not handling Keydown event for Esc Key

Grids for WPF Forum

Posted 7 years ago by Pankaj Sood
Version: 11.2.0553
Avatar

Hi Members,

I am having a property grid inside a user control and i write a keydown event for this property grid. This is working fine whenever i press any key but in case of Esc Key its not working. Please suggest

Regards

Pankaj Sood

[Modified 7 years ago]

Comments (5)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Pankaj,

The PropertyGrid has default handling for the Escape key, which tries to cancel any changes made by the end-user. You would either need to handle the PreviewKeyDown event, or clear the PropertyGrid.EscapeKeyDownDelegates collection to disable the default handling.


Actipro Software Support

Posted 7 years ago by Pankaj Sood
Avatar

Hi,

Thanks for replying, I have already written the PreviewKeyDown event for my PropertyGrid but control is not firing the event whenever i press Escape Key also please inform where i find the PropertyGrid.EscapeKeyDownDelegates collection so that i may clear it.

Regards

Pankaj

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

If I add the following code to our WinForms PropertyGrid Functionality demo and hook up the handler to the PropertyGrid's PreviewKeyDown, then I can see the Escape key coming through:

private void propGrid_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e) {
    System.Diagnostics.Debug.WriteLine(string.Format("************ {0}", e.Key));
}

This comes through even if you do not clear the EscapeKeyDownDelegates collection, which is on the PropertyGrid control. You would only need to clear this collection if you don't want the PropertyGrid to handle the Escape key in the KeyDown down event. If you are using the PreviewKeyDown event, then that occurs before any of the PropertyGrid code is executed.


Actipro Software Support

Posted 7 years ago by Pankaj Sood
Avatar

Hi,

Thanks for replying. I would like to inform you that my application is not a winform application it’s a WPF application. I didn’t used the property grid control directly I create a custom class “MyPropGrid” that inheriting the PropertyGrid Class. Inside the MyPropGrid I initialize the keydown and previewkeydown events.

Public class MyProGrid : PropertyGrid

{

//constructor

MyProGrid()

{

KeyDown += MyProGrid_KeyDown;

}

}

Private MyProGrid_KeyDown ( object sender, Keyeventargs e)

{

TextBox tb = e.OriginalSource as TextBox;

if (tb != null && e.Key == Key.Escape)

{

// Do some functionality

}

}

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Pankaj,

Yes, the "WinForms PropertyGrid Functionality demo" is just the name of a sample in our Sample Browser, which shows how our PropertyGrid for WPF mimics the WinForms PropertyGrid.

Your code snippet above uses the KeyDown event, not the PreviewKeyDown event. The KeyDown event can be handled by any number of controls before it reaches the PropertyGrid control, as it bubbles up the visual tree from the control with focus. But the PreviewKeyDown event tunnels down the visual tree, so the PropertyGrid control would see the event before any of it's descendents.

If this doesn't help please put together a small sample project that reproduces your issue and email it over then we can take a closer look. Be sure to remove any executables or change the extension of the zip file to ensure it gets past our email filters.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 12 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.