Click here to Skip to main content
Licence CPOL
First Posted 2 Oct 2006
Views 41,117
Downloads 90
Bookmarked 18 times

TreeView control with tri-state logic

By | 12 Jan 2010 | Article
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)

About the Author

Dalibor Carapic

Web Developer

Croatia Croatia

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General2 suggestion PinmemberMr.PoorEnglish2:25 3 Mar '10  
GeneralRe: 2 suggestion PinmemberDalibor Carapic2:42 3 Mar '10  
JokeRe: 2 suggestion PinmemberMr.PoorEnglish3:39 3 Mar '10  
Generalstrange issue PinmemberMr.PoorEnglish1:02 3 Mar '10  
QuestionHow this ended... PinmemberPaw Jershauge1:32 12 Jan '10  
AnswerRe: How this ended... PinmemberDalibor Carapic5:17 12 Jan '10  
GeneralRe: How this ended... PinmemberPaw Jershauge5:31 12 Jan '10  
GeneralRe: How this ended... PinmemberPaw Jershauge5:33 12 Jan '10  
GeneralRe: How this ended... PinmemberDalibor Carapic8:43 12 Jan '10  
GeneralRe: How this ended... PinmemberPaw Jershauge11:35 12 Jan '10  
AnswerRe: How this ended... PinmemberMr.PoorEnglish0:50 3 Mar '10  
GeneralNo Works Pinmemberluisxvarg21:31 11 Jan '10  
GeneralRe: No Works PinmemberDalibor Carapic1:21 12 Jan '10  
Questiona question from Zin Mar PinadminSean Ewington16:13 27 May '07  
AnswerRe: a question from Zin Mar PinmemberDalibor Carapic20:16 27 May '07  
QuestionHow? Pinmemberlessms14:43 20 May '07  
AnswerRe: How? Pinmemberlessms14:56 20 May '07  
AnswerRe: How? Pinmemberdc100020:46 20 May '07  
GeneralRe: How? Pinmemberlessms4:41 21 May '07  
GeneralRe: How? Pinmemberdc10004:55 21 May '07  
GeneralRe: How? Pinmemberlessms5:19 21 May '07  
GeneralRe: How? PinmemberDalibor Carapic20:31 21 May '07  
GeneralMaking the tri state tree theme aware Pinmembersitussoft3:49 23 Mar '07  
Generalproblem adding this project to a ASP.NET website Pinmembermohsen nowruzi4:33 6 Nov '06  
GeneralRe: problem adding this project to a ASP.NET website PinmemberChris Richner2:37 15 Mar '07  

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.

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