Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# System.Windows.Forms.TreeView: Stop auto expand/collapse on double-click (and execute another handler)

Is there a simple way to disable the auto-expand/collapse of a TreeView node when it is double-clicked? I've been unable to find an answer to this question that works without checking in BeforeExpand/BeforeCollapse if the current system time matches that expected for a double-click - overriding OnNodeMouseDoubleClick and/or OnDoubleClick does not seem to suffice.

Or, is checking the system time and seeing if it fits a double-click the only way to do this?

Thanks for your help, -Walt

like image 277
Walt W Avatar asked Aug 20 '09 18:08

Walt W


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


1 Answers

Solved: Actually, the entire solution was at http://www.developersdex.com/gurus/code/831.asp . Apparently OnNodeMouseDoubleClick() is not called in the WM_LBUTTONDBLCLK handler for TreeView at all . . . it's called in the LBUTTONUP handler. So, The following is what's at that site:

    protected override void DefWndProc(ref Message m) {
        if (m.Msg == 515) { /* WM_LBUTTONDBLCLK */
        }
        else
            base.DefWndProc(ref m);
    }

If you want to halt handling to the left of the node, then in OnNodeMouseDoubleClick() do the following:

if (e.X >= e.Node.Bounds.Left) {
    return;
}
like image 148
Walt W Avatar answered Sep 29 '22 08:09

Walt W