แก้ไข

แชร์ผ่าน


Tree Control Label Editing

The user can directly edit the labels of items in a tree control (CTreeCtrl) 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 EditLabel 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 TVN_BEGINLABELEDIT 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 TVN_ENDLABELEDIT notification message. The lParam parameter is the address of a NMTVDISPINFO structure. The item member is a TVITEM 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 TVN_BEGINLABELEDIT notification message, you can get a pointer to the edit control used for label editing by using the GetEditControl member function. You can call the edit control's SetLimitText 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 after TVN_BEGINLABELEDIT is sent.

See also

Using CTreeCtrl
Controls