Share via


Tree Control Label Editing

OverviewSample

The user can directly edit the labels of items in a tree control () that has the TVS_EDITLABELS style. The user begins editing by clicking the label of the item that has the focus. An application begins editing by using the member function. The tree control sends the notification when editing begins and when it is canceled or completed. When editing is completed, you are responsible for updating the item's label, if appropriate.

When label editing begins, a tree control sends a notification message. By processing this notification, you can allow editing of some labels and prevent editing of others. Returning 0 allows editing, and returning nonzero prevents it.

When label editing is canceled or completed, a tree control sends a notification message. The lParam parameter is the address of a structure. The item member is a structure that identifies the item and includes the edited text. 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.

During label editing, typically in response to the notification message, you can get a pointer to the edit control used for label editing by using the member function. You can call the edit control's member function to limit the amount of text a user can enter or subclass the edit control to intercept and discard invalid characters. Note, however, that the edit control is displayed only afterTVN_BEGINLABELEDIT is sent.

See Also   Windows Common Controls and MFC Classes