C# WinForms: Disabling the Collapse on a double-click for TreeView

Posted on 2012-09-15
Last Modified: 2012-09-15
I coded the double-click event to edit the node double-clicked on.  So I no longer want the default behavior which collapses the node tree for the Node double-clicked on.

How do I stop this?

Question by:newbieweb
    LVL 40

    Accepted Solution

    Create your own TreeView by inheriting from the standard one:
    Public Class YourTreeView
    	Inherits System.Windows.Forms.TreeView
    	Protected Overrides Sub OnNodeMouseDoubleClick(e As TreeNodeMouseClickEventArgs)
    		'Your alternate code
    	End Sub
    End Class

    Open in new window

    Inheritance lets you inherit all the functionnality of the standard TreeView. But since you overrides the method that triggers NodeMouseDoubleClick, you are the one in control on that event.

    Compile your code, and your custom TreeView should appear in an extra tab at the top of the ToolBox. Use it anywhere you want in place of the standard TreeView. No need to code the thing in the application, it is now part of your new "enhanced" TreeView.

    Author Closing Comment

    Thanks.  Good idea...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now