DoubleClick in TreeView
-
Hey, How to turn off behaviour of TreeView control that if you double click on branch with children than it will expand/collapse? Overriding OnDoubleClick() doesn't work as some other event does collapse/expand.
I am assuming that the "OnDOubleClick" function you are talking about is a function you implemented as a callback in the parent window class, to process the NM_DBLCLK notification message from the tree control. This message is sent to the parent window AFTER the tree control finishes its default processing. You need to subclass the tree control and handle the WM_LBUTTONDBLCK message appropriately.
-
Hey, How to turn off behaviour of TreeView control that if you double click on branch with children than it will expand/collapse? Overriding OnDoubleClick() doesn't work as some other event does collapse/expand.
Solution de Uberness: ----------------------------------------------- using System; namespace UberControls { public class TreeViewNonExpanding : System.Windows.Forms.TreeView { private bool incomingDoubleClick = false; protected override void WndProc(ref System.Windows.Forms.Message m) { switch( m.Msg ) { case 0x0203: // WM_LBUTTONDBLCLK this.incomingDoubleClick = true; break; case 0x0202: // WM_LBUTTONUP this.incomingDoubleClick = false; break; default: break; } base.WndProc (ref m); } protected override void OnBeforeExpand(System.Windows.Forms.TreeViewCancelEventArgs e) { if( incomingDoubleClick == true ) e.Cancel = true; base.OnBeforeExpand (e); } } }