Windows - Forms - TreeView - C#
While working on TreeView implementation came across a strange issue.
Double click is event is not been properly called w.r.t. check box associated with node.
Following are the scenario that has been observed:
While working on TreeView implementation came across a strange issue.
Double click is event is not been properly called w.r.t. check box associated with node.
Following are the scenario that has been observed:
- TreeView does not fire DoubleClick event the very first time.
- TreeView may fire DoubleClick event when a user only single clicks.
- TreeView does not fire BeforeCheck/AfterCheck events at all when user double clicks the checkbox image.
Solution:
This is something Microsoft need to figure it out.
Workaround:
Disable the double click event from firing in TreeView so that unreliable functionality can be taken out.
Only click event will be allowed and as far as end user will find no issue with double click and single click.
Step 1:
Build you application with all the relevant functionality.
Step 2:
In Form.Designer.cs file add following code at end.
Inheriting TreeView class and suppressing the double click (WM_LBUTTONDBLCLK message) in derived class. Then derived class is being used for processing.
Inheriting TreeView class and suppressing the double click (WM_LBUTTONDBLCLK message) in derived class. Then derived class is being used for processing.
namespace System.Windows.Forms { public class TestTreeView : TreeView { protected override void WndProc(ref Message m) { if (m.Msg == 0x203) // identified double click m.Result = IntPtr.Zero; else base.WndProc(ref m); } } }
Step 3:
In Form.Designer.cs file change references of TreeView class with inherited class TestTreeView.
private void InitializeComponent() { this.tvBaseDirectory = new System.Windows.Forms.TestTreeView(); }
Step 4:
BUILD IT and RUN IT
Reference
Reference
Thank you! That works great!
ReplyDeleteWelcome...
Deletecan u provide same code in vb.net
ReplyDeleteI have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteFinal Year Projects for CSE in Dot Net
.Net Training in Chennai
Final Year Project Centers in Chennai
Dot Net Training in Chennai
Hi,
ReplyDeletei have read your blog
thanks for posting
We are leading Laparoscope distributor in Delhi ncr
Visit Our website : https://www.genuinemedica.net/laparoscopy-hand-instruments
Hi,
ReplyDeleteThanks for great post
We are Air Purifier Dealers in South Delhi contact us for more info
informative post
ReplyDeleteBasil Badwan
��Jaipur escorts
ReplyDelete��Jaipur escorts
��Jaipur escorts
��Delhi escorts
��Guwahati escorts
��Guwahati escorts
��Guwahati escorts
��Guwahati escorts