Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Windows Vista Treeview

2.64/5 (10 votes)
12 Feb 2008CPOL 1   2.7K  
A custom made TreeView with Windows Vista look.

Vista_TreeView.jpg

Introduction

This is a custom TreeView control which provides a Windows Vista look.

Background

The code is a combination of three different codes made by José Manuel Menéndez Poo, Xasthom, and Stephen J Whiteley. As most of the code is made by Stephen, his copyright messages have been left.

This code is a part of the SQLmail.org project, an Open Source project whose goal is to make a MySQL based mail client. All messages should be stored in a SQL database which will provide extremely fast search. As I would like to have Windows Vista look for the whole program, almost all controls are customized. In the SQLmail.org project, you can find a Vista customized button, a radio button, a checkbox, a toolstrip, and a datagrid, and the way to use them.

Using the Code

It is very easy to use this control. Download the class from the link at the top of the page and import it in your project. Build your project, and you will find it as a new control in the Toolbox.

You can use a custom node like this:

VB
Dim NewNode As New WindowsVistaNode
NewNode.Name = "myname"
NewNode.Text = "text"
' If you need an icon next to the node, add an ImageList
' on the form, import images in it (Images, Collection),
' on the treeview select the added ImageList in the ImageList property
NewNode.ImageKey = "image.gif" ' name of the image in the ImageList collection
NewNode.SelectedImageKey = "image.gif"
' name of the image which will be drawn when the node is selected, 
' for example, a closed folder for default and an open one for selected

'
' If you want to change a font on the specific node
NewNode.Font = New Font(TreeView1.Font.FontFamily, _
                        TreeView1.Font.Size, FontStyle.Bold)
' Title property is a custom property which allowes you
' to have different sections in a treeview.
' Title node cannot be selected, cannot be closed (always expanded),
' cannot be highlighted when the mouse is hovering
' and the text is always left alligned
NewNode.Title = True
NewNode.Text = UCase(NewNode.Text) ' use it for title nodes
'
Folder_Tree.Nodes.Add(NewNode)

License

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