Allowing Users to Edit Item Labels

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

To allow users to edit the item labels, the treeview control should be created with the TVS_EDITLABELS style. Either you can set this style in the resource editor, or in the call to Create() or in PreCreateWindow() if you are using the CTreeView class.

You should then handle the TVN_BEGINLABELEDIT and the TVN_ENDLABELEDIT notifications. You can use the class wizard to add the handler functions. Actually it is not necessary to handle the TVN_BEGINLABELEDIT notification but it is a good idea to do so and limit the length of the text that the user may enter into the edit control.

void COutline::OnBeginLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)

   // Limit text to 127 characters

   *pResult = 0;

It is necessary for you to handle the TVN_ENDLABELEDIT notification. If you don't do so, then although the user will be able to edit the labels, but at the end of the edit the value of the label will be set to the previous value. The handler is also a good place to update any internal data structure you maintain to track the state of the tree view control.

void COutline::OnEndLabelEdit(NMHDR* pNMHDR, LRESULT* pResult)
   // Set result to TRUE to accept the changes
   *pResult = TRUE;


  • Tree Control in a dialog - Win32

    Posted by SLyons on 05/26/2004 10:23am

    I created a tree control in a dialog box in Win32. I prevent editing returning TRUE from TVN_BEGINLABELEDIT. The selection highlighting on the entry disappears. Clicking on the entry again won't work until a different entry has been selected. Has anybody got any ideas about how to get round this problem. Simon

  • Restricting editing

    Posted by Legacy on 10/23/2002 12:00am

    Originally posted by: Simon

    It there a possibility to allow edit only some items and the others not?

    I would like to edit only (in my application) red items, but blue should be fixed and not possible to edit. Is that possible just with graying the choices on the menu, but what is if the user will try to edit label just with left click on text.


  • Does't work for TreeCtrl inDialog box.

    Posted by Legacy on 08/10/2001 12:00am

    Originally posted by: Srini

    Yes, It did not.

  • Example worked a treat for me, but how do I force a refresh of callback text?

    Posted by Legacy on 08/01/2001 12:00am

    Originally posted by: hal9000lives

    Hi there,

    The web-page explanation was more than enough for me to get it working in a CTreeView.

    One problem: My text comes from LPSTR_TEXTCALLBACK's and the strings are not requested again through the OnGetDispInfo, so the display does not change even though my data does.

    How do I tell the tree to refresh an item's text?


  • Does not seem to work when TreeCtrl in a view...

    Posted by Legacy on 07/31/2001 12:00am

    Originally posted by: Fred

    Edit label box never appears...

  • Editing label

    Posted by Legacy on 06/05/2001 12:00am

    Originally posted by: shinilkp

    if u could givean example of editing using TVN_ENDLABELEDIT

  • It is diffcult to edit label accroding with this sugestion

    Posted by Legacy on 08/14/2000 12:00am

    Originally posted by: szChen

    /*The Following are My Codes*/
    void CViewTree::OnBeginlabeledit(NMHDR* pNMHDR, LRESULT* pResult)
    // TODO: Add your control notification handler code here

    CTreeCtrl& cThisTree = GetTreeCtrl();

    *pResult = 0;

  • How do I have RichEdit Labels in a TreeView/TreeControl

    Posted by Legacy on 05/09/2000 12:00am

    Originally posted by: Mark

    Is there any way I can have RichEdit Labels in a TreeView.
    Any help would be appreciated.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • This case study will highlight the opportunity for mobile and cloud technologies in the Public Sector—specifically for state, local and federal government agencies -where secure mobile application access can offer key productivity gains

  • Whether a mandate to secure all web and mobile apps comes from a newly enlightened CIO or in response to a major security breach, beginning even a small application security program can be a daunting task. How will you know how many digital assets you have, let alone their risk profile? In this webinar we explore how, using a cloud solution like Fortify on Demand, even the largest organizations can begin to scan apps immediately and rapidly scale an application security program. Identify and risk rank assets, …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date