Click here to Skip to main content
Click here to Skip to main content

TreeView control with tri-state logic

, 12 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
An override of the default .NET 2.0 TreeView control which supports tri-state logic for its tree nodes.

Sample Image - ThreeStateTreeView.png

Introduction

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.

Issues 

  • 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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dalibor Carapic
Web Developer
Croatia Croatia
No Biography provided

Comments and Discussions

 
General2 suggestion PinmemberMr.PoorEnglish3-Mar-10 3:25 
GeneralRe: 2 suggestion PinmemberDalibor Carapic3-Mar-10 3:42 
JokeRe: 2 suggestion PinmemberMr.PoorEnglish3-Mar-10 4:39 
Generalstrange issue PinmemberMr.PoorEnglish3-Mar-10 2:02 
QuestionHow this ended... PinmemberPaw Jershauge12-Jan-10 2:32 
AnswerRe: How this ended... PinmemberDalibor Carapic12-Jan-10 6:17 
GeneralRe: How this ended... PinmemberPaw Jershauge12-Jan-10 6:31 
GeneralRe: How this ended... PinmemberPaw Jershauge12-Jan-10 6:33 
GeneralRe: How this ended... PinmemberDalibor Carapic12-Jan-10 9:43 
GeneralRe: How this ended... PinmemberPaw Jershauge12-Jan-10 12:35 
AnswerRe: How this ended... PinmemberMr.PoorEnglish3-Mar-10 1:50 
GeneralNo Works Pinmemberluisxvarg11-Jan-10 22:31 
GeneralRe: No Works PinmemberDalibor Carapic12-Jan-10 2:21 
Questiona question from Zin Mar PinadminSean Ewington27-May-07 17:13 
AnswerRe: a question from Zin Mar PinmemberDalibor Carapic27-May-07 21:16 
QuestionHow? Pinmemberlessms20-May-07 15:43 
AnswerRe: How? Pinmemberlessms20-May-07 15:56 
AnswerRe: How? Pinmemberdc100020-May-07 21:46 
GeneralRe: How? Pinmemberlessms21-May-07 5:41 
GeneralRe: How? Pinmemberdc100021-May-07 5:55 
GeneralRe: How? Pinmemberlessms21-May-07 6:19 
GeneralRe: How? PinmemberDalibor Carapic21-May-07 21:31 
GeneralMaking the tri state tree theme aware Pinmembersitussoft23-Mar-07 4:49 
Generalproblem adding this project to a ASP.NET website Pinmembermohsen nowruzi6-Nov-06 5:33 
GeneralRe: problem adding this project to a ASP.NET website PinmemberChris Richner15-Mar-07 3:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 12 Jan 2010
Article Copyright 2006 by Dalibor Carapic
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid