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

  • Chuze Fitness is a fast-growing fitness chain with over 21 locations spanning California, Arizona and Colorado. Chief information and marketing officer, Kris Peterson, explains why access to fast and reliable Wi-Fi is a "must have" service at their gyms and why they switched to Ruckus Cloud Wi-Fi. Chuze Fitness needed to provide a good user experience to the hundreds of guests streaming music, podcasts and videos as they worked out. They also needed to adequately cover their sprawling 20-40,000 square foot …

  • This IDC study assists senior IT leaders in assessing the current state of their hybrid cloud management processes, governance models, technologies, and skills to identify gaps and create a road map for better aligning the organization's management model and tools with the emerging needs of complex, dynamic self-service hybrid cloud environments. This IDC MaturityScape identifies five maturity stages for hybrid cloud management based on a set of specific people, process, and technology dimensions and outcomes. …

Most Popular Programming Stories

More for Developers

RSS Feeds

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