PRB: ESC and ENTER Keys Do Not Work When You Edit Labels in TreeView

Article translations Article translations
Article ID: 130691 - View products that this article applies to.
This article was previously published under Q130691
Expand all | Collapse all


When you edit labels in a TreeView control, you should be able to press the ESC key to cancel the changes or press the ENTER key to accept the changes. However, when the TreeView control is contained in a dialog box, IsDialogMessage processes the ESC and ENTER keystrokes and does not pass them on to the edit control that is created by the TreeView control. The result is that the keystrokes have no effect.


The tree view control creates and subclasses the edit control that is used for in-place editing. The subclass procedure does not handle the WM_GETDLGCODE message that is sent by IsDialogMessage, which results in default handling of the keystrokes by IsDialogMessage.


To work around this problem, subclass the edit control in response to the TVN_BEGINLABELEDIT notification that is sent by the tree view control when the tree view is about to start label editing for an item. To obtain the edit control's window handle, send the tree view control a TVM_GETEDITCONTROL message.

The subclass procedure should handle the WM_GETDLGCODE message by returning DLGC_WANTALLKEYS. This allows the tree view's subclass procedure to handle ESC and ENTER keystrokes.


Article ID: 130691 - Last Review: July 11, 2005 - Revision: 1.2
  • Microsoft Platform Software Development Kit-January 2000 Edition
kbtreeview kbprb kbctrl KB130691

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from