tags:

views:

31

answers:

3

I have a class derived from CTreeCtrl. In some circumstances the user might be editing it and I would like to programmatically cancel the edit which is currently in progress.

How do I do this? There doesn't seem to be any appropriate function of the class which would do that, or if I have to send it some message it's not immediately obvious to me what the message is that I should send.

A: 

To determine if the user is editing a label, you have to wait for the folling messages: TVN_BEGINLABELEDIT and TVN_ENDLABELEDIT.

To cancel, just set the focus to another node.

dwo
Yes, I know what TVN_ENDLABELEDIT is, but I wanted to know how I get the edit control to generate one of those. I appreciate the focus suggestion, although that seems slightly awkward - I have to find another node (which potentially might not exist) and then I don't really want it focused afterwards... thanks for the suggestion though.
Peter
A: 

So I've eventually discovered that I can fake an Escape button press to the edit control:

tree.GetEditControl()->SendMessage(WM_KEYDOWN, VK_ESCAPE, 1);

This seems to cancel editing appropriately.

Peter
+1  A: 

I believe this is possible by sending the tree control the TVM_ENDEDITLABELNOW message, or by using the TreeView_EndEditLabelNow macro.

flashk
Huh, and there is an EndEditLabelNow() method of CTreeCtrl. I must be going blind in my old age... thanks for the answer!
Peter