CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 1999
    Location
    germany | berlin
    Posts
    70

    renaming tree control item ?

    hi there!

    I want to rename an item of a tree control. I used the following
    code:


    void CMyarchivDlg::OnBeginlabeleditTree1(NMHDR* pNMHDR, LRESULT* pResult)
    {
    CString sText;
    TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR;
    UpdateData(TRUE);
    sText.Format("%s",m_MyTreeControl.EditLabel(m_MyTreeControl.GetSelectedItem()));
    m_MyTreeControl.SetItemText(m_MyTreeControl.GetSelectedItem(),sText);
    UpdateData(FALSE);
    *pResult = 0;
    }




    Unfortunately it doesn't work.
    Can anyone give my a hint what's wrong ?

    THANX in advance

    greetz
    cheops



  2. #2
    Join Date
    May 1999
    Location
    ALABAMA, USA
    Posts
    9,917

    Re: renaming tree control item ?

    You should not handle it in TVN_BEGINLABELEDIT notification handler. It is used for different purpose.

    In TVN_ENDLABELEDIT notification handler, check for a pszText member of the TVITEM structure contained TV_DISPINFO* pTVDispInfo = (TV_DISPINFO*)pNMHDR.

    If this member is empty do not do anything. Editing has been cancelled.
    Only if otherwise set item text to pszText member.

    All that UpdateData, and other stuff is not needed for this purpose.

    You should check pszText and then:


    m_MyTreeControl.SetItemText(pTVDispInfo->item.hItem, pTVDispInfo->item.pszText);




    This is it!


    I don't do it for ratings. Important is if you let me know if solution worked.
    Good luck in your journey in a C++ land.

    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  3. #3
    Join Date
    Jun 2002
    Location
    Richmond, VA
    Posts
    104

    A followup, I am able to rename my items, but

    I have a bit of a problem elsewhere.

    I catch, using the ON_NOTIFY_REFLECT TVN_KEYDOWN, when the user presses delete, and I delete the tree item...

    Unfortunately, sometimes the user presses delete in the slight pause that occurs after clicking on an item in the tree but before the item label becomes editable. Thus, the Tree item is deleted, in a sense, out from under the editing label. How can I, in the TVN_KEYDOWN message handler, prevent any label editing messages from being carried out?

  4. #4
    Join Date
    Jul 2003
    Posts
    147

    Re: renaming tree control item ?

    Can you do a check to see that the selected item is the same as the item that you are trying to edit?

    Code:
    void OnTvnBeginLabelEdit(NMHDR *pNMHDR, LRESULT *pResult)
    {
       LPNMTVDISPINFO pTVDispInfo = reinterpret_cast<LPNMTVDISPINFO>(pNMHDR);
       if(pTVDispInfo->item.hItem != tree.GetSelectedItem())
       {
          //Don't allow the edit
          *pResult = 1;
       }
       else
       {
          //Handle edit ...
          *pResult = 0;
       }
    }
    Good Luck!

  5. #5
    Join Date
    Jun 2002
    Location
    Richmond, VA
    Posts
    104

    Re: renaming tree control item ?

    Thanks! I actually had the codes reversed and was setting pResult to 0 to disable instead of 1...I ended up with a variation of your suggestion, thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured