C# TreeView – CheckBox – Double Click – BUG – for VISTA and Win7


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);
 }
}

12 Responses to “C# TreeView – CheckBox – Double Click – BUG – for VISTA and Win7”

  1. Andy Bonner Says:

    Hi Anando

    Your a star!!

    I thought I was cracking up until I found your post and simple solution.

    Thanks
    Andy

  2. FRoZeN Says:

    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.

  3. Pradeep Says:

    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

  4. Andrew Bullock Says:

    Thanks! This was driving me insane!

  5. plock Says:

    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?

  6. Elena Says:

    Thanks a lot)))))))

  7. Alex Says:

    Thank you very much. You’re some kind of… code hero 😀


Leave a comment