Click here to Skip to main content
11,412,834 members (74,566 online)
Click here to Skip to main content

Advanced TreeView for .NET

, 10 Jul 2006
Rate this:
Please Sign up or sign in to vote.
The TreeViewAdv control is designed to replace the standard .NET TreeView. It can do the same things, plus a number of advanced features like multi-selection or multi-column view.

TreeViewAdv in Multi-Column mode


Working on several different projects, I was needed to display and edit hierarchical data. Of course, the first thing you will do is to use the standard .NET TreeView control. It works pretty well if you only need basic features. But learning this control to do something more complex is not an easy job. I could not find an alternative TreeView control which is free and fully meets my needs, so finally I decided to write my own.

The architecture of this control comes mainly from the Java Swing component, with some modifications. These are the key features of the TreeViewAdv control:

  • Model-View architecture - Will be covered in a separate section of this article.
  • Multiselection - Maybe the first limitation which you will find in the standard TreeView is that it’s not possible to select more then one node.
  • Unlimited number of controls for each node - You can display three icons + a CheckBox + two Labels.
  • Multicolumns - You can split the TreeView into several columns.
  • Load on Demand - Lazy load of child nodes.
  • Drag & Drop highlighting - Dynamically highlight the drop position.
  • 100% pure .NET code - No WinAPI is used in this control.

The following screenshots illustrate the TreeViewAdv features:

Drag&Drop highlighting


Using ComboBox to edit node

Model-View Architecture

I really like the Model-View pattern, and decided to use it in this control. The main idea of this pattern is to split the model (business object) from its visualization (control). If the model changes, it notifies the view by firing corresponding events. The view asks the model for details, if needed, and displays the changes. The model is described by ITreeModelInterface:

public interface ITreeModel
    IEnumerable GetChildren(TreePath treePath);
    bool IsLeaf(TreePath treePath);

    event EventHandler<TreeModelEventArgs> NodesChanged; 
    event EventHandler<TreeModelEventArgs> NodesInserted;
    event EventHandler<TreeModelEventArgs> NodesRemoved; 
    event EventHandler<TreePathEventArgs> StructureChanged;

It’s very simple, and you need to implement only two methods. GetChildren should return the list of child nodes of the specified parent (empty for root nodes). IsLeaf method tells TreeView whether it should try to read child nodes of the specified parent. If you wish TreeView to dynamically track model changes, you need to use one of several events of the ITreeModel interface. The most common is the StructureChanged event, which cause the TreeView to fully refresh the specified node (or empty, for the whole model). For example, see the default implementation of the ITreeModel interface – the TreeModel class.

To specify the exact node in the model, TreePath class is used. It stores the path from the root to the node, in the FullPath property.

public class TreePath
    public object[] FullPath{ get; }
    public object LastNode{ get; }
    public object FirstNode{ get; }

Using TreeView

In the source code, you can find two examples of how to use TreeViewAdv. The simplest way is to use TreeModel. All you need is to populate it with data and display it in the view:

_model = new TreeModel();
_model.Nodes.Add(new Node("Root"));
_tree.Model = _model;

The Node class, which is used in TreeModel, contains only the ‘Text’ and ‘IsChecked’ properties. If you need additional properties, you can create an ancestor of the Node class and use it in TreeModel.

But to use the full power of the TreeViewAdv, you should create your own realization of the ITreeModel interface. See the folder browser presented in the source code, for an example.

Customizing TreeView

There are a number of properties which help to customize the look and behavior of the TreeView. The main ones are:

  • Model - Assign your model to this property to display it.
  • NodeControls - The collection of controls which will be used to visualize the model. You should provide at least one NodeControl in order to see the model.
  • LoadOnDemand - Read all child nodes at start-up or when the parent node expands.
  • SelectionMode - Single (no multi-selection), Multi, MultiSameParent (children of only one node can be selected).
  • UseColumns - Display data in columns or not.
  • Columns - The collection of columns. For each column, you can specify its header, width and alignment.


The standard TreeView can display only one icon, CheckBox, and Label for each node. In TreeViewAdv, you can use any number of NodeControl. All controls must inherit from the ‘NodeControl’ abstract class. Inherited classes should contain the code to draw the control and the code to respond on user actions – mouse and keyboard events.


This is the class diagram of all NodeControls provided by the library:

Class diagram

The BindableControl class provides a ‘DataPropertyName’ which is used in the control to read and write data to the node. All that you need is to specify the name of the property of your class.

Terms and Conditions

The TreeViewAdv control is provided as free software with open source code. You can use it in your applications if the original copyright is kept.

The latest version of TreeViewAdv is always available here. Please feel free to add your comments and suggestions in the forum there.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Andrey Gliznetsov
Software Developer
Russian Federation Russian Federation
No Biography provided

Comments and Discussions

QuestionLooks great.. Pin
Mohan Sawant at 28-Jan-15 0:34
memberMohan Sawant28-Jan-15 0:34 
QuestionGrouping Pin
Brendt.w at 8-Sep-14 1:03
memberBrendt.w8-Sep-14 1:03 
QuestionTreeview in Asp.Net Pin
Member 11026198 at 21-Aug-14 20:56
memberMember 1102619821-Aug-14 20:56 
QuestionIn one PC, the tree node's text is not show. Pin
mail_main at 27-May-14 18:37
membermail_main27-May-14 18:37 
QuestioniedEdit node Pin
Member 9505756 at 15-May-14 20:33
memberMember 950575615-May-14 20:33 
QuestionNodeButton Pin
HansDampft at 24-Mar-14 19:25
memberHansDampft24-Mar-14 19:25 
Questionreceiving error on conversion Pin
Agent_Spock at 22-Feb-14 8:34
professionalAgent_Spock22-Feb-14 8:34 
QuestionisLeaf is always false, so leaf state icon does not display Pin
Member 10559105 at 29-Jan-14 14:58
memberMember 1055910529-Jan-14 14:58 
QuestionAdvanced TreeView on SourceForge Pin
pzajic at 14-Jan-14 1:08
memberpzajic14-Jan-14 1:08 
QuestionRedraw issue after editing a cell?? Pin
i00 at 6-Jan-14 19:17
professional i006-Jan-14 19:17 
QuestionLooks simple code samples...made me to look out for another.... Pin
AnandChavali at 22-Dec-13 7:02
memberAnandChavali22-Dec-13 7:02 
AnswerRe: Looks simple code samples...made me to look out for another.... Pin
i00 at 7-Jan-14 16:07
professional i007-Jan-14 16:07 
Questionis it possible to configure columns to autosize? Pin
carga at 10-Dec-13 10:07
membercarga10-Dec-13 10:07 
QuestionThis looks fantastic but... Pin
mtthwbrnd at 8-Oct-13 19:06
membermtthwbrnd8-Oct-13 19:06 
QuestionTree gets deleted when scrolling Pin
Shochat at 16-Sep-13 22:53
memberShochat16-Sep-13 22:53 
QuestionUsing VisualStyles for row selection/hilighting [modified] Pin
curtis1757 at 30-Aug-13 12:05
membercurtis175730-Aug-13 12:05 
Questiondirection tree from right to left (arabic) Pin
Member 10213747 at 16-Aug-13 6:50
memberMember 1021374716-Aug-13 6:50 
QuestionWith Custom treeview column I am not able to bind ComboBoxColumn Data Pin
RBajania at 17-Jul-13 1:52
memberRBajania17-Jul-13 1:52 
QuestionHow to install the treeview Pin
Member 9504844 at 25-Apr-13 23:21
memberMember 950484425-Apr-13 23:21 
AnswerRe: How to install the treeview Pin
Ch4m3l30n at 17-Jun-13 14:30
memberCh4m3l30n17-Jun-13 14:30 
BugGetting Error while working in combo box Pin
suresh11101983 at 7-Apr-13 22:36
membersuresh111019837-Apr-13 22:36 
Question2 different label for one node Pin
Member 9869450 at 21-Mar-13 23:51
memberMember 986945021-Mar-13 23:51 
QuestionMove Up & down functionality Pin
Ram Shelke at 17-Mar-13 0:23
memberRam Shelke17-Mar-13 0:23 
AnswerRe: Move Up & down functionality Pin
William Winner at 18-Mar-13 3:42
memberWilliam Winner18-Mar-13 3:42 
QuestionTreeview binding in database Pin
Member 9671635 at 19-Dec-12 1:39
memberMember 967163519-Dec-12 1:39 
QuestionAdd Node after a node Pin
PapyRef at 29-Nov-12 12:07
memberPapyRef29-Nov-12 12:07 
Suggestion[My vote of 2] Lack of examples... Pin
Niyazi Yarar at 23-Nov-12 13:25
memberNiyazi Yarar23-Nov-12 13:25 
GeneralMy vote of 5 Pin
Simon_ at 12-Nov-12 7:52
memberSimon_12-Nov-12 7:52 
QuestionExpand Node Pin
Kenneth Psaila at 5-Oct-12 2:45
memberKenneth Psaila5-Oct-12 2:45 
QuestionShow/Hide TreeNode Pin
mccallug at 3-Oct-12 7:14
membermccallug3-Oct-12 7:14 
Does anyone know a way to set the visibility of a tree node? I can't find a way to hide individual nodes or even remove them.
QuestionScrolling bug Pin
are_all_nicks_taken_or_what at 18-Sep-12 6:07
memberare_all_nicks_taken_or_what18-Sep-12 6:07 
NewsRe: Scrolling bug Pin
Niyazi Yarar at 24-Sep-12 4:44
memberNiyazi Yarar24-Sep-12 4:44 
QuestionHangs in FindModel() Pin
are_all_nicks_taken_or_what at 18-Sep-12 5:56
memberare_all_nicks_taken_or_what18-Sep-12 5:56 
AnswerRe: Hangs in FindModel() Pin
are_all_nicks_taken_or_what at 18-Sep-12 6:03
memberare_all_nicks_taken_or_what18-Sep-12 6:03 
QuestionCPOL license terms Pin
Barbara Evans at 15-Aug-12 0:18
memberBarbara Evans15-Aug-12 0:18 
QuestionRefreshing a node with out collapsing the tree Pin
David Koenig at 12-Jul-12 21:12
memberDavid Koenig12-Jul-12 21:12 
AnswerSet the Startup Project to SampleApp to avoid exception "Assembly doesn't contain any UserControl types." Pin
David Deley at 6-Jul-12 20:01
memberDavid Deley6-Jul-12 20:01 
QuestionVertical Column Headers Pin
MatthysDT at 6-Jul-12 1:24
memberMatthysDT6-Jul-12 1:24 
QuestionExport to CSV or Excel Pin
ksanghavi at 21-Jun-12 11:39
memberksanghavi21-Jun-12 11:39 
QuestionSynchronize scrolling? Pin
denciaq at 31-May-12 21:57
memberdenciaq31-May-12 21:57 
AnswerRe: Synchronize scrolling? Pin
Member 10166589 at 23-Jul-13 2:06
memberMember 1016658923-Jul-13 2:06 
GeneralMy vote of 5 Pin
korolevsa at 14-Apr-12 4:26
memberkorolevsa14-Apr-12 4:26 
QuestionTrouble Downloading Pin
Jason Gauthier at 10-Apr-12 12:10
memberJason Gauthier10-Apr-12 12:10 
BugLosing reference to the TreeNodeAdv inside node controls Pin
Member 8578151 at 5-Apr-12 2:20
memberMember 85781515-Apr-12 2:20 
GeneralMy vote of 5 Pin
wdydxf at 11-Mar-12 18:08
memberwdydxf11-Mar-12 18:08 
QuestionHow to filter the nodes with their parents accordingly? Pin
Member 4226640 at 9-Jan-12 23:14
memberMember 42266409-Jan-12 23:14 
SuggestionIcons being drawn incorrectly Pin
joehoper at 21-Nov-11 10:18
memberjoehoper21-Nov-11 10:18 
GeneralMy vote of 5 Pin
joehoper at 21-Nov-11 9:52
memberjoehoper21-Nov-11 9:52 
Generalabout the tree develop thinking Pin
lovejun at 26-Oct-11 17:20
memberlovejun26-Oct-11 17:20 
SuggestionRedo in VCS 2010 Express, please. VCS Errors are in V1.7.0.0 and versionless zip file. Pin
Lou Arnold at 12-Oct-11 16:57
memberLou Arnold12-Oct-11 16:57 

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
Web01 | 2.8.150427.1 | Last Updated 10 Jul 2006
Article Copyright 2006 by Andrey Gliznetsov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid