none
Three-state checkbox in TreeView

    Question

  •  

    Not so sure if this is a right forum for my question...

    I currently develop a Windows application using C# + .NET 2.0 - 3.5 with VS2008.  I want to have a tree view with checkboxes that have three states: checked, unchecked, and gray-checked.  Very much like the VS installation program.

     

    But the .Net tree-view control has only 2 state checkbox: checked/unchecked.  How can I make the treeview has the 3-state checkbox?  Can someone give me some sample code?

     

    thanks in advance

     

     

    Tuesday, December 25, 2007 6:41 PM

Answers

  • Hi David,

     

    If you use Spy++ to examine the TreeView control, you will find that the checkboxes in the TreeView are not real checkbox controls, they are images drawn by the TreeView control. Currently, the TreeView control does not suppor the three states checkbox yet.

     

    If you really wanted to get this done, you have to custom-draw the TreeView control for each nodes. You have to maintain each node's CheckBox states and draw three different checkbox images in TreeView.DrawNode event. Anyway, this is not a trivial task. The link below contains some sample code about basic custom-draw concept of TreeView control:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2591153&SiteID=1

     

    Thanks.

     

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     

    Thursday, December 27, 2007 3:15 AM

All replies

  • Hi David,

     

    If you use Spy++ to examine the TreeView control, you will find that the checkboxes in the TreeView are not real checkbox controls, they are images drawn by the TreeView control. Currently, the TreeView control does not suppor the three states checkbox yet.

     

    If you really wanted to get this done, you have to custom-draw the TreeView control for each nodes. You have to maintain each node's CheckBox states and draw three different checkbox images in TreeView.DrawNode event. Anyway, this is not a trivial task. The link below contains some sample code about basic custom-draw concept of TreeView control:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2591153&SiteID=1

     

    Thanks.

     

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

     

    Thursday, December 27, 2007 3:15 AM
  • Hi Jeffrey,

     

    the link you provided is broken.

    Monday, November 29, 2010 2:27 PM
  • I think it is better to change image of TreeNode (and have checked, unchecked, and 3rd state) instead of owner drawing.
    Tuesday, February 14, 2012 10:58 AM