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

解决方案 »

  1.   

    上述好象是Tree Control
    我现用的是CTreeView类,不知道怎样关联TreeCtrl
      

  2.   

    大侠们!
    已生成CTreeView类,如何加入树形图?
    急急急
      

  3.   

    CTreeView是在CTreeCtrl的基础上包了一层.
    由CTreeView取CTreeCtrl可以用CTreeCtrl& CTreeView::GetTreeCtrl( ) const;取出CTreeCtrl你就可以象下面这样做啦:
    TVINSERTSTRUCT tvRoot;
    tvRoot.hParent = NULL;
    tvRoot.hInsertAfter = NULL;
    tvRoot.item.mask = TVIF_TEXT;
    tvRoot.item.pszText = "所有组号";
    HTREEITEM hTreeRoot = m_treeCtrl.InsertItem(&tvRoot);
    CString str;
    for (int i = 0; i < 10; i++)
    {
        str.Format(_T("第%d组"), i);
        HTREEITEM hTreeGroupItem = m_treeCtrl.InsertItem(str, hTreeRoot);
    }上面的例程中
    在根结点是"所有组号"
    其下是10个子结点,分别是;
    第0组
    ...
    第9组当然你也可以象上面那面再插入一层...
    ...