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

This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
When you edit labels in a TreeView control, you should be able to press theESC 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.
Cause
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.
Resolution
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.
Properties

Article ID: 130691 - Last Review: 01/07/2015 06:10:55 - Revision: 2.0

  • kbnosurvey kbarchive kbctrl kbprb kbtreeview KB130691
Feedback