[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1014
  • Last Modified:

C# WinForms: I can not override OnNodeMouseDoubleClick event for a TreeView

I created a new object which inherits from the TreeView I created in the designer.  In the C#, I:

- hide that TreeView
- I construct a new TreeView based on the child class
- assign the value to it from the designer TreeView, to save work for myself
- I show the new TreeView and add it to the Controls list for the form


But, when I double click a collapsed node it expands the node before hitting the breakpoint in my overriden function:

        protected override void OnNodeMouseDoubleClick(TreeNodeMouseClickEventArgs e)
        {
        base.OnNodeMouseDoubleClick(e);
        }

I want to stop the collpase expand behavior and get that under my control, so I can only expand/collapse when I choose to.

What am I doing wrong?
0
newbieweb
Asked:
newbieweb
1 Solution
 
Naman GoelSoftware engineer 1Commented:
This is default behavior of treeview but you can handle it like following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public class MyTreeView: TreeView
    {
        bool isCancelExpand = false;
        protected override void OnBeforeExpand(TreeViewCancelEventArgs e)
        {
            base.OnBeforeExpand(e);
            e.Cancel = isCancelExpand;
            isCancelExpand = false;
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            isCancelExpand = e.Clicks > 1;
        }

   
    }
}

Open in new window

0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now