Allowing user editing on CTreeCtrl

Posted on 1998-10-01
Last Modified: 2013-11-20
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??
Question by:dd021197
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1322805
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.

Author Comment

ID: 1322806
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.


Author Comment

ID: 1322807
The points are yours timop if I can get a bit more info.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 1322808
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.

Accepted Solution

cramer091498 earned 50 total points
ID: 1322809
look at
for a sample solution

Author Comment

ID: 1322810
the points are yours


Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question