This bug arises in Vista and Win7 whenever you double click on the TreeView item checkbox. Double click will not fire any even but it will change the check status of that item which leads to inconsistent behavior of TreeView item checking.
Solution : use this NewTreeView class instead of TreeView default class.
using System; using System.Windows.Forms; public class NewTreeView : TreeView { protected override void WndProc(ref Message m) { if (m.Msg == 0x203) { m.Result = IntPtr.Zero; } else base.WndProc(ref m); } }
April 21, 2010 at 1:09 AM
Hi Anando
Your a star!!
I thought I was cracking up until I found your post and simple solution.
Thanks
Andy
April 21, 2010 at 4:53 AM
Thank you.
September 27, 2010 at 1:44 PM
Just ran into the Vista/Win7 checked treeview bug.. you just saved me a lot of headache, i dont understand what the code does tho, and im a little curious.
November 30, 2010 at 5:29 PM
Thank You for the great tip. I have solved my issue with your help.
Here is the Microsoft Bug Link for more information…
https://connect.microsoft.com/VisualStudio/feedback/details/374516/treeview-control-does-not-fire-events-reliably-when-double-clicking-on-checkbox
June 6, 2011 at 9:59 AM
Thanks! This was driving me insane!
June 15, 2011 at 2:11 AM
The only problem with this solution is that it also blocks the double click event on the actual treeview item as well, not just the item’s checkbox. Is there a way to check if the double click was on a checkbox and ignore that, but let the other’s pass through?
June 28, 2011 at 4:24 AM
if you have some suggestion regarding this side effect then please provide.
July 19, 2011 at 1:50 AM
I have no idea how to fix this problem. I was hoping you might have some ideas?
October 9, 2012 at 6:01 PM
Well, you can just do a hittest and see if the user is clicking on the checkbox or not.
August 25, 2011 at 11:45 AM
Thanks a lot)))))))
September 6, 2011 at 5:54 PM
[…] https://anandopaul.wordpress.com/2010/01/01/c-treeview-checkbox-double-click-bug-for-vista-and-win7/ […]
October 16, 2012 at 9:28 PM
Thank you very much. You’re some kind of… code hero 😀