• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

Allowing user editing on CTreeCtrl

Easy Question:
How to I allow the user to edit the items in a tree control
I have set the window style on creation, but how do I start
the edit process off - so I can receive the messages (start and end edit)?? Has anyone some source for me to look at??
1 Solution
To allow the user to edit the items you must use TVS_EDITLABELS style.

m_treeCtrl.ModifyStyle(0, TVS_EDITLABELS ); // editing is allowed

When label editing begins, a tree view control sends its parent window a TVN_BEGINLABELEDIT notification message.
When label editing is canceled or completed, a tree view control sends its parent window a TVN_ENDLABELEDIT notification message.
dd021197Author Commented:
Thanks, the message is now sent. But I still don't understand
how the editing takes place - I want to set it up like explorer
what code do I put where? Do I handle the CEdit control or
is that taken care of. All I have done is set the style on
creation and modified the style. The messages are being called
okay now - but I still can't actually edit the labels.

dd021197Author Commented:
The points are yours timop if I can get a bit more info.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hi dd !

Handle some mouse or keyboard event (dbl click / Enter /etc) where you wish to activate your editing. Enter the following line

CEdit * pEdit = EditLabel();

CTreeCtrl manages the Edit control. If you wish, you can subclass the edit control in OnBeginLabelEdit() using GetEditCtrl().

Now put code for OnBeginLabelEdit() & OnEndLabelEdit(). You can use GetEditCtrl() to retrieve ptr to this edit control. Use any of the edit controls functions.

Use TV_DISPINFO structure on OnEndLabelEdit to retrieve all sorts of info. Refer documentation. You are responsible for updating the item's label, if appropriate, perhaps after validating the edited string. The pszText member of TV_ITEM is 0 if editing is canceled.

Say what, you should refer to the following documentation.
"Tree Control Label Editing"

If you have any questions regarding Subclassing the edit control, I will gladly help you.
look at
for a sample solution
dd021197Author Commented:
the points are yours

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now