Allowing Users to Edit Item Labels

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)
{
   TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;

   // Limit text to 127 characters
   GetEditControl()->LimitText(127);

   *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;
}


Comments

  • 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

    Reply
  • 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.

    Thanks.

    Reply
  • Does't work for TreeCtrl inDialog box.

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

    Originally posted by: Srini

    Yes, It did not.

    Reply
  • 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?

    Thanks

    Reply
  • 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...

    Reply
  • 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

    Reply
  • 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)
    {
    TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
    // TODO: Add your control notification handler code here

    CTreeCtrl& cThisTree = GetTreeCtrl();
    cThisTree.GetEditControl()->LimitText(127);

    *pResult = 0;
    }

    Reply
  • 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.
    Thanks
    Mark

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

Top White Papers and Webcasts

  • Find out how a simple and free assessment can lead to IT Transformation. #GetModern

  • The relentless march of end user organizations toward cloud services continues, despite long-standing fears about information security, the lack of visibility into cloud provider security controls, and the shortcomings of controls available to those who utilize cloud services. And while more and more security-as-a-service (SaaS) solutions and application programming interfaces (APIs) are becoming available, many cloud service providers just aren't moving fast enough to address today's enterprise needs. Read …

Most Popular Programming Stories

More for Developers

RSS Feeds

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