Treeview change text of node before node is in an editable state

Answered Treeview change text of node before node is in an editable state

  • Wednesday, July 18, 2012 12:17 PM
     
     
    How do I change text of treeview node(by "long click" of mouse) before node is in an editable state(user can rename the label text) without overriding "OnNotifyMessage"?
    • Edited by OrionWalli Wednesday, July 18, 2012 2:16 PM
    •  

All Replies

  • Thursday, July 19, 2012 5:39 AM
     
     

    please specify which programming language you are using?

    And what is the project type? From your description, I think the question is not about Win32 application.

    If you are working with a C# windows Forms application, please move to Visual C# General forum.

    If it is CLR windows Forms application, please try Common Language Runtime CLR forum.


    Please mark this reply as answer if it helps you! Thanks for your cooperation! Good Luck to you.

  • Thursday, July 19, 2012 6:25 AM
     
     

    Hi Rebecca, 

    I am using C++ cli as the language and the question is about treeview in windows forms.

    Thank You.

  • Thursday, July 19, 2012 12:31 PM
     
     
    Set Edit Lables property  of Tree to TRUE

    Thanks, Renjith V R

  • Thursday, July 26, 2012 3:04 AM
    Moderator
     
     

    Hi OrionWalli,

    I'd like to mark Renjith's reply as answer. If you have any questions or do not agree, you can post back and unmark it. We'll continue working with you on this issue.

    Thanks for your understanding.
    Best regards,


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

  • Thursday, July 26, 2012 6:42 AM
     
     
    The proposed answer seem to work only for the situation where the mouse right click is involved. I need the solution for the "long left click" where the node turns to an editable state with the text already changed to some preset name. Thank you.
  • Friday, July 27, 2012 9:27 PM
     
      Has Code

    Actually i didn't understand what is your requirement. If you want to change the text of TreeView when you click on it then see the following sample. I am not sure you need this

    void TreeCtrlEx::OnLButtonUp(UINT nFlags, CPoint point)
    {
    	HTREEITEM hTree = GetSelectedItem();
    	SetItemText(hTree,_T("hellow"));
    	EditLabel(hTree);
    	CTreeCtrl::OnLButtonUp(nFlags, point);
    }


    Thanks, Renjith V R

  • Monday, July 30, 2012 9:40 AM
     
     

    Hi Renjith,

    Thanks for your reply.

    I want the node to be in an editable state i.e for renaming. This is somewhat like renaming a folder/file which is already selected and then clicking on the folder name with the left click holding the button down for some amount of time. 


  • Monday, July 30, 2012 1:52 PM
     
     Answered Has Code

    Could you please elaborate your question. I understood that

    You have a TreeView and you click( right or left) on one item. That item need to be in editable state. This can be done using the same code in my last post. Only the mouse handler will be changed respective to right or left button of mouse. Also remove SetItemText() call.

    void TreeCtrlEx::OnLButtonUp(UINT nFlags, CPoint point)
    {
    	HTREEITEM hTree = GetSelectedItem();
    	EditLabel(hTree);
    	CTreeCtrl::OnLButtonUp(nFlags, point);
    }
    
    void TreeCtrlEx::OnRButtonUp(UINT nFlags, CPoint point)
    {
    	HTREEITEM hTree = GetSelectedItem();
    	EditLabel(hTree);
    	CTreeCtrl::OnLButtonUp(nFlags, point);
    }

    if you want edit on mouse button down, try HitTest() inside the mouse handlers.


    Thanks, Renjith V R


  • Thursday, August 02, 2012 7:15 AM
     
     
    This works now. Thanks Rehjith.