Allowing Users to Edit Item Labels

Thursday Aug 6th 1998 by Zafir Anjum

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)

   // 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;
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved