none
How to replace OnDoubleClick (in treeview) RRS feed

  • Question

  • this->treeView1->MouseDoubleClick += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::treeView1_EditField);
    
    private: System::Void treeView1_EditField(Object ^sender, System::Windows::Forms::MouseEventArgs ^e){
    			 TreeNode ^node;
    			 try{
    				 //some code
      node = this->treeView1->SelectedNode; this->treeView1->LabelEdit = true; node->BeginEdit(); //some code
    } catch(...){ //handle exceptions } }

    Here is what i want to get:

    after double clicking on TreeNode it should edit, but not expand.

    So as I thought i need a code like ^:

    but it also Expand a TreeNode

    I thought that maybe if I somehow could replace OnDoubleClick or remove all MOuseDoubleClick events it would work as I want, but i can't find any example how to do it.

     

    Can anybody help me? :)

     

    Edit:

    One more thing which I want to get is when i double click on plus "+" or minus "-" sign (to expand / collapse childs) it shouldn't edit a TreeNode but only expand+collapse.


     

    Tuesday, November 2, 2010 9:55 AM

Answers

  • The solution provided in your link basically handles the WindowProc() and return swithout passing it on to the base class method:

     

    protected override void WndProc(ref Message m)
    {
       switch(m.Msg )
       {
          case WM_LBUTTONDBLCLK:
             MessageBox.Show ("db click");
          return;
         break;
       }
       base.WndProc (ref m);
    }

    BTW, your code looks like it is C++/CLI.. So for correct syntax, please search. Here's one ref: http://www.functionx.com/vccli/general/methods.htm

    -Seetharam


    • Marked as answer by Michal Szecel Monday, November 8, 2010 12:02 PM
    Tuesday, November 2, 2010 9:54 PM
  • Well, the solution is to catch the double-click event before it is passed on to the DoubleMouseClick event handler...and that is usually done in the WndProc().

     

    This code does exactly that!

    protected override void WndProc(ref Message m)
    {
       switch(m.Msg )
       {
          case WM_LBUTTONDBLCLK:
             MessageBox.Show ("db click");
          return;  ///----------->> RETURNS without calling the BASE.WNDPROC below.
         break;
       }
       base.WndProc (ref m);
    }

    Try overriding WndProc in your code.

    -Seetharam

    Wednesday, November 3, 2010 3:04 PM
  • ok Seetharam answer works fine, but it is disabling all double click events so i had to change my code a lot to work ok.

    Well for me its kinda strange that you have to catch all events generated by w Windows::Forms object just to disable double click -> and after disabling it when you add any event to MouseDoubleClick it wont work - all operations need to be implemented in WndProc method.

    But well I'm the begginer so it could be the reason :P

    correct syntax for C++/CLI looks exactly:

    ref class myTree :
    public System::Windows::Forms::TreeView
    {
    public:    myTree(void) : TreeView(){}

    protected: virtual void WndProc(Message %m) override{
                   switch(m.Msg){
                       //double click
                        case 0x203:
                             //You need to implement all double click operations here
                            return;
                            break;
                    }
                   TreeView::WndProc(m);
               }

    }

    Monday, November 8, 2010 12:01 PM

All replies

  • Derive a custom tree control from CTreeCtrl class and override the OnDraw(), OnRButtonDown().. etc methods as per your wish.

    Subclassing the Windows common controls using MFC 

    Tuesday, November 2, 2010 11:32 AM
  • ok I've tried to do something liek this:

     

    ref class myTree :
    public System::Windows::Forms::TreeView
    {
    public:
        myTree(void): TreeNode(){}


    protected:
        virtual void MouseDoubleClick(Object ^sender, System::Windows::Forms::MouseEventArgs ^e){

    System::Windows::Forms::MessageBox::Show("AAA");

    }

    };

     

    So if I think right it should show messagebox with "AAA" instead of expanding a treenode. But it doesnt work - what am I doing wrong?

     

    I also found a solution here: http://bytes.com/topic/c-sharp/answers/225859-double-click-treeview

    but I dont know why it should work and how to make it in VC++. Can anybody help me? :)

    Tuesday, November 2, 2010 8:05 PM
  • The solution provided in your link basically handles the WindowProc() and return swithout passing it on to the base class method:

     

    protected override void WndProc(ref Message m)
    {
       switch(m.Msg )
       {
          case WM_LBUTTONDBLCLK:
             MessageBox.Show ("db click");
          return;
         break;
       }
       base.WndProc (ref m);
    }

    BTW, your code looks like it is C++/CLI.. So for correct syntax, please search. Here's one ref: http://www.functionx.com/vccli/general/methods.htm

    -Seetharam


    • Marked as answer by Michal Szecel Monday, November 8, 2010 12:02 PM
    Tuesday, November 2, 2010 9:54 PM
  • http://www.functionx.com/vccli/general/methods.htm

    shows me how to add an event handler - I knew it before - I want to somehow destroy existing event handler for double click and put on its place my own event handler :P dunno if it is clear...

    for example:

    TreeView's DouleMouseClick event handler cause exapanding/collapsing child TreeNodes - I want to delete this action. I want only to edit a field after double click.

    Tuesday, November 2, 2010 10:58 PM
  • Well, the solution is to catch the double-click event before it is passed on to the DoubleMouseClick event handler...and that is usually done in the WndProc().

     

    This code does exactly that!

    protected override void WndProc(ref Message m)
    {
       switch(m.Msg )
       {
          case WM_LBUTTONDBLCLK:
             MessageBox.Show ("db click");
          return;  ///----------->> RETURNS without calling the BASE.WNDPROC below.
         break;
       }
       base.WndProc (ref m);
    }

    Try overriding WndProc in your code.

    -Seetharam

    Wednesday, November 3, 2010 3:04 PM
  •  

    Hi,

     

    I'm very interested your issue, did you solve your problem?

    If so please share the solution with us and mark the right answers.

    If not please let me know.

     

    Have a nice day!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, November 5, 2010 6:40 AM
    Moderator
  • ok Seetharam answer works fine, but it is disabling all double click events so i had to change my code a lot to work ok.

    Well for me its kinda strange that you have to catch all events generated by w Windows::Forms object just to disable double click -> and after disabling it when you add any event to MouseDoubleClick it wont work - all operations need to be implemented in WndProc method.

    But well I'm the begginer so it could be the reason :P

    correct syntax for C++/CLI looks exactly:

    ref class myTree :
    public System::Windows::Forms::TreeView
    {
    public:    myTree(void) : TreeView(){}

    protected: virtual void WndProc(Message %m) override{
                   switch(m.Msg){
                       //double click
                        case 0x203:
                             //You need to implement all double click operations here
                            return;
                            break;
                    }
                   TreeView::WndProc(m);
               }

    }

    Monday, November 8, 2010 12:01 PM