Articles in this section
Category / Section

What is the reason for ProcessDialogKey of the form hosting TreeViewAdv not triggers escape when WinForms TreeViewAdv has focus and escape key?

1 min read

Handle OnKeyDown event in TreeViewAdv

If TreeViewAdv has focus and Escape key is pressed, ProcessDialogKey event of the TreeViewAdv gets triggered only when the TreeNodeAdv is in edit mode (Setting LableEdit to true). Hence ProcessDialogKey of the Form hosting TreeViewAdv not triggers Escape if TreeViewAdv has focus and Escape key is pressed.

To override this behavior, we can derive TreeViewAdv and override KeyDown event and call base.ProcessDialogKey to trigger Escape .

C#

protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
{
   base.ProcessDialogKey(e.KeyData);
   if(e.KeyData == System.Windows.Forms.Keys.Escape)
   {
      e.Handled = false;
   }
   base.OnKeyDown(e);
}

VB

Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs)
   MyBase.ProcessDialogKey(e.KeyData)
   If e.KeyData = System.Windows.Forms.Keys.Escape Then
      e.Handled = False
   End If
   MyBase.OnKeyDown(e)
End Sub

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied