
This article illustrates the use of a treeview in a directory tree user control. You can use this control to visually select files or directories from any file structure on your computer system.
The treeview has been a common way to display hierarchies of data. In C# it's fairly easy to manipulate a tree because the design of the treeview is based on a recursive Node Structure:

This design was drawn using WithClass 2000 UML Design Tool
The treeview uses these node structures for handling most of its data population. The images from the tree view come from an ImageList component. The ImageList must be constructed seperately, and the icons used in the imagelist are added to the Images Collection from pictures created in an image editor (like mspaint or something):

The ImageList is then associated to the TreeView via the ImageList property:

When nodes are constructed, they are assigned indexes that point to a particular image in the list.
Now let's take a good look at our directory tree user control. The code for populating the directory nodes takes advantage of the Directory class in the System.IO namespace. A tree is built by first constructing the node with the name, image index, and image index when a node is selected. Then the node is added to the parent node.

A DPosted Oct 1, 2007, 6:30 PM
Did you ever post a reply to the first message submitted and if you did could you please forward your answer on to me as well. I am not having any luck removing the full path from the nodes without causing an exception at this time. Here is the first message submitted in case you have forgotten: "hi, currently each node name is given the full path to the folder/file. is it possible to only have each node labelled by the folder/file name alone and not the full path. " Another question I have is there a way to go about programmatically selecting more than one treenode at a time, e.g. like a multi-select. Thanks, Adrian
robertPosted Jul 4, 2007, 12:19 PM
hi, currently each node name is given the full path to the folder/file. is it possible to only have each node labelled by the folder/file name alone and not the full path. i.e. similar to how it is displayed in the image above?? thanks robert