ARTICLE

WPF TreeView control in VB.NET

Posted by Rohatash Kumar Articles | XAML in VB.NET March 09, 2011
This article defines hierarchical or parent/child relationship view of data using treeview control.
Download Files:
 
Reader Level:

TreeView control

TreeView control can be used for any data that can be represented in a hierarchy. The tree view provides an object oriented hierarchical or parent/child relationship view of data and meta-data. The most common example of a tree view is Windows Explorer's directory structure where disk drives contain folders, folders contain sub-folders and folders contain files.

property

Items Property - Items property is used to Initial collection of the nodes for the tree.

Foreground and Background property

The Background and Foreground property represents the background and foreground color of the TreeView control.

Now using Items property of the TreeView control to initial collection of the nodes.

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

    <Grid x:Name="LayoutRoot" Background="White" Height="412">

        <TreeView Height="400" HorizontalAlignment="Left" Margin="30,9,0,0" Name="TreeView1" VerticalAlignment="Top" Width="318" Background="SpringGreen">

            <TreeViewItem Header="Item1" Name="TreeViewItem2" Foreground="Blue" Background="Aqua">

                <TreeViewItem Header="Sub Item1" Foreground="Brown" Background="Tan">

                    <TreeViewItem Header="Example1" Foreground="DarkRed" Background="Teal" />

                </TreeViewItem>

            </TreeViewItem>

            <TreeViewItem Header="Item2" Background="SteelBlue" Name="TreeViewItem4">

                <TreeViewItem Header="Sub Item1" Background="Yellow">

                    <TreeViewItem Header="Example1" Background="Yellow" />

                </TreeViewItem>

                <TreeViewItem Header="Sub Item2" Background="Crimson">

                    <TreeViewItem Header="Example1" Background="Teal" />

                    <TreeViewItem Header="Example2" Background="Plum" />

                </TreeViewItem>

            </TreeViewItem>

            <TreeViewItem Header="Item3" Background="Wheat" Foreground="Brown" Name="TreeViewItem5">

                <TreeViewItem Header="Sub Item1" Background="YellowGreen">

                    <TreeViewItem Header="Example1" Background="Magenta" />

                </TreeViewItem>

                <TreeViewItem Header="Sub Item2" Name="TreeViewItem1" Background="Red">

                    <TreeViewItem Header="Example1" Background="Purple" />

                    <TreeViewItem Header="Example2" Background="CadetBlue" Foreground="Blue" />

                </TreeViewItem>

                <TreeViewItem Header="Sub Item3" Name="TreeViewItem3" Background="Yellow" Foreground="DarkGreen">

                    <TreeViewItem Header="Example1" Background="Indigo" Foreground="DarkRed" />

                    <TreeViewItem Header="Example2" Background="Lime" />

                    <TreeViewItem Header="Example3" Background="DarkBlue" />

                </TreeViewItem>

            </TreeViewItem>

        </TreeView>

    </Grid>

 </Window>

Now run the application.

tv1.gif

TreeView1.gif

Now expand all the nodes.

tv2.gif

TreeView2.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor