Click here to Skip to main content
13,356,318 members (59,144 online)
Click here to Skip to main content
Add your own
alternative version


57 bookmarked
Posted 6 Apr 2008


, 6 Apr 2008
Rate this:
Please Sign up or sign in to vote.
TreeView with multiple columns


This control is supposed to display hierarchical data in a TreeView while providing the possibility to append additional information to each item.


I needed to present data in a hierarchical structure but it was required to display additional information for each item. At first, I appended all this information to the TreeNodeItem's text which was quite unclear for the user.

Using the Code

To use the multi column TreeView in your own application, declare the control in any of your windows or controls. TreeListView exposes all properties of ListView plus AllowsColumnReorder and Columns.

<local:TreeListView AllowsColumnReorder="True">

Both properties correlate with the AllowsColumnReorder and Columns properties of GridView which is documented here.

Hierarchical Data Template

In order to provide the tree with a way to retrieve child nodes, you must either declare a HierarchicalDataTemplate or a DataTemplateSelector.

TreeListView is only going to use the ItemsSource property of the HierarchicalDataTemplate or DataTemplateSelector because all information is visualized in the same manner (in rows). Therefore, a declaration as follows is sufficient:

    <HierarchicalDataTemplate ItemsSource="{Binding Children}"/>


It is vital to declare at least one column which the TreeListView is going to use to visualize the data. MSDN provides sufficient information about declaring GridViewColumns so I am not going to go into any details.

The only new thing about declaring GridViewColumns is that at least one column must contain a TreeListViewExpander which is a ToggleButton that can expand its row and indents all contents in its column.

            <StackPanel Orientation="Horizontal">
                <!--<span class="code-comment">The Expander Button (can be used in any column 
                (typically the first one))--></span>
                <!--<span class="code-comment">The data to display in this column--></span>
                <TextBlock Text="{Binding}"/>

And that's it!

Points of Interest

It would probably be a good idea to implement all features of GridView. Unfortunately I do not have the time to do that right now.


  • 6th April, 2008
    • First release
    • Fixed file download


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


About the Author

United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralFile Pin
gurveysc8-Apr-08 4:55
membergurveysc8-Apr-08 4:55 
GeneralRe: File Pin
tillmyspace8-Apr-08 21:32
membertillmyspace8-Apr-08 21:32 
GeneralRe: File Pin
Member 38002106-Aug-09 5:06
memberMember 38002106-Aug-09 5:06 
GeneralRe: File Pin
tillmyspace9-Apr-08 11:06
membertillmyspace9-Apr-08 11:06 
GeneralRe: File Pin
gurveysc9-Apr-08 11:17
membergurveysc9-Apr-08 11:17 
GeneralRe: File Pin
Thoris25-Jul-08 6:20
memberThoris25-Jul-08 6:20 
GeneralRe: File Pin
gurveysc25-Jul-08 6:33
membergurveysc25-Jul-08 6:33 
GeneralRe: File Pin
Sunil Jampa28-Sep-08 21:50
memberSunil Jampa28-Sep-08 21:50 
how can i download this source???

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
Web01 | 2.8.180111.1 | Last Updated 6 Apr 2008
Article Copyright 2008 by tillmyspace
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid