Click here to Skip to main content
13,139,569 members (54,131 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 2 Oct 2006

TreeView control with tri-state logic

, 12 Jan 2010
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


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 ( 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


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


About the Author

Dalibor Carapic
Web Developer
Croatia Croatia
No Biography provided

You may also be interested in...


Comments and Discussions

General2 suggestion Pin
Mr.PoorEnglish3-Mar-10 2:25
memberMr.PoorEnglish3-Mar-10 2:25 
GeneralRe: 2 suggestion Pin
Dalibor Carapic3-Mar-10 2:42
memberDalibor Carapic3-Mar-10 2:42 
JokeRe: 2 suggestion Pin
Mr.PoorEnglish3-Mar-10 3:39
memberMr.PoorEnglish3-Mar-10 3:39 
Generalstrange issue Pin
Mr.PoorEnglish3-Mar-10 1:02
memberMr.PoorEnglish3-Mar-10 1:02 
QuestionHow this ended... Pin
Paw Jershauge12-Jan-10 1:32
memberPaw Jershauge12-Jan-10 1:32 
AnswerRe: How this ended... Pin
Dalibor Carapic12-Jan-10 5:17
memberDalibor Carapic12-Jan-10 5:17 
GeneralRe: How this ended... Pin
Paw Jershauge12-Jan-10 5:31
memberPaw Jershauge12-Jan-10 5:31 
GeneralRe: How this ended... Pin
Paw Jershauge12-Jan-10 5:33
memberPaw Jershauge12-Jan-10 5:33 
GeneralRe: How this ended... Pin
Dalibor Carapic12-Jan-10 8:43
memberDalibor Carapic12-Jan-10 8:43 
GeneralRe: How this ended... Pin
Paw Jershauge12-Jan-10 11:35
memberPaw Jershauge12-Jan-10 11:35 
AnswerRe: How this ended... Pin
Mr.PoorEnglish3-Mar-10 0:50
memberMr.PoorEnglish3-Mar-10 0:50 
GeneralNo Works Pin
luisxvarg11-Jan-10 21:31
memberluisxvarg11-Jan-10 21:31 
GeneralRe: No Works Pin
Dalibor Carapic12-Jan-10 1:21
memberDalibor Carapic12-Jan-10 1:21 
Questiona question from Zin Mar Pin
Sean Ewington27-May-07 16:13
adminSean Ewington27-May-07 16:13 
AnswerRe: a question from Zin Mar Pin
Dalibor Carapic27-May-07 20:16
memberDalibor Carapic27-May-07 20:16 
QuestionHow? Pin
lessms20-May-07 14:43
memberlessms20-May-07 14:43 
AnswerRe: How? Pin
lessms20-May-07 14:56
memberlessms20-May-07 14:56 
AnswerRe: How? Pin
dc100020-May-07 20:46
memberdc100020-May-07 20:46 
GeneralRe: How? Pin
lessms21-May-07 4:41
memberlessms21-May-07 4:41 
GeneralRe: How? Pin
dc100021-May-07 4:55
memberdc100021-May-07 4:55 
GeneralRe: How? Pin
lessms21-May-07 5:19
memberlessms21-May-07 5:19 
GeneralRe: How? Pin
Dalibor Carapic21-May-07 20:31
memberDalibor Carapic21-May-07 20:31 
GeneralMaking the tri state tree theme aware Pin
situssoft23-Mar-07 3:49
membersitussoft23-Mar-07 3:49 
Generalproblem adding this project to a ASP.NET website Pin
mohsen nowruzi6-Nov-06 4:33
membermohsen nowruzi6-Nov-06 4:33 
GeneralRe: problem adding this project to a ASP.NET website Pin
Chris Richner15-Mar-07 2:37
memberChris Richner15-Mar-07 2:37 

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

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

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