Recently I needed to add a TreeView control to my project which required a tri-state type checkbox on its nodes. The standard .NET Windows Forms TreeView control supports adding checkboxes to its node, but it does not support tri-state logic on them. After reading a good article (http://www.cherea.de/bitbucket/checktree/checktree.html) about how to do it in MFC I've decided to add this functionality to the Windows Forms TreeView control.
Setting custom state images
The .NET TreeView control is simply a wrapper around the standard Tree control which is a part of the Windows common controls. Tree control supports two image lists. One image list is used to display standard icons which you can also set in the .NET TreeView, while the other image list is used to set state images. By giving our own image list to the Tree control, we can choose what we want to display instead of the normal checkboxes provided by TreeView control. The provided ThreeStateTreeView control, in combination with the provided ThreeStateTreeNode does exactly that.
Using the code
Using the control is the same as using the standard TreeView control. Instead of instantiating the TreeView control, just instantiate the ThreeStateTreeView control.
- setting the state only works after the node has been added to the tree and only after the tree handle has been created (tree has been displayed)
- by clicking on the new checkbox you only cycle between checked/unchecked, third state can only be changed programmaticaly