Click here to Skip to main content
13,798,571 members
Click here to Skip to main content
Add your own
alternative version


126 bookmarked
Posted 1 Oct 2002

FolderTreeView Control

, 25 Oct 2002
Rate this:
Please Sign up or sign in to vote.
A simple explorer-like FolderTreeView control for C#

Sample Image


This is an all-new version of the FolderTreeView control I posted here at CodeProject some weeks ago. The control now starts in the Desktop namespace, and a new drilling method has been added so the startup folder can be specified. Please note that this control is not intended to have all of the functionality of the actual Windows Explorer TreeView - it is a light-weight control designed for use in projects where you want to supply a treeview for folder navigation, without supporting windows shell extensions. If you are looking for a control that supports shell extensions, you should be looking at the excellent ËxplorerTreeControl submitted by Carlos H Perez here at the CodeProject website.

How It Works

After calling the InitFolderTreeView() method, a dummy Desktop note is created as the root node, and then the shell's Desktop namespace is iterated to populate the first level nodes. The child nodes are then iterated, checking only for the presence of sub-child nodes. If sub-child nodes are found, a dummy node is inserted so that the [+] will be displayed for folders that can be expanded. When the BeforeExpand event fires, the folder being expanded is checked for a dummy node. If a dummy is present, it is removed and the node's children are re-populated. If the node's children have already been populated, no further action occurs.


The FolderTreeView control is based on 3 classes:

  • FolderTreeView - The FolderTreeView implementation
  • ShellOperations - Supporting Shell Operations
  • ExtractIcons - Shell Icon Extractor

The control naturally derives from the System.Windows.Forms.TreeView, exposing 1 new property, GetSelectedNodePath() which returns the currently selected node's full path. There are 2 new methods: InitFolderTreeView() must be called to populate the TreeView - normally, you would call this in your Form's OnLoad event. The 2nd method is DrillToFolder(string folderPath) - this will recurse through the tree looking for the specified folder path, returning a boolean to indicate if the search was successful or not.

The method used to retrieve the icon for the Desktop root node works fine, but is perhaps not the best way to go about it. This control has NOT been tested in Win9x, NT or 2000 - feedback on these OSs would be much appreciated. Of course, if you improve this control, I would appreciate the update, and if you have any feedback to offer, please post it below.


Version 1.11

  • Updated the GetDesktopIcon() method so it returns the shell's small desktop icon rather than the large version
  • Added code so that the Desktop node would return the full desktop folder path

I have now tested the code on Windows Me without problem - feedback on how it works with other OSs would be appreciated!


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

Web Developer
Thailand Thailand
Furty will code for food.

You may also be interested in...


Comments and Discussions

GeneralRe: Hi Furty Pin
tunt5-Nov-03 17:47
membertunt5-Nov-03 17:47 
GeneralRe: Hi Furty Pin
Furty6-Nov-03 13:23
memberFurty6-Nov-03 13:23 
GeneralCool tool Pin
FootFunk2-May-03 10:21
memberFootFunk2-May-03 10:21 
QuestionCould anyone give me a link to similar control in win32 or WTL ? Pin
Ilushka20-Feb-03 23:46
memberIlushka20-Feb-03 23:46 
Questionicons have black shadows? Pin
scottfm7-Feb-03 15:25
memberscottfm7-Feb-03 15:25 
AnswerRe: icons have black shadows? Pin
Furty8-Feb-03 4:51
memberFurty8-Feb-03 4:51 
GeneralRe: icons have black shadows? Pin
mingot19-Mar-03 17:15
membermingot19-Mar-03 17:15 
GeneralRe: icons have black shadows? Pin
Marc Clifton27-May-03 7:35
protectorMarc Clifton27-May-03 7:35 
GeneralHidden folders Pin
Scott Lee24-Jan-03 4:58
memberScott Lee24-Jan-03 4:58 
GeneralRe: Hidden folders Pin
Tagsmas6-Jan-04 2:59
memberTagsmas6-Jan-04 2:59 
AnswerRe: Hidden folders [modified] Pin
Jos Branders31-Oct-09 6:25
memberJos Branders31-Oct-09 6:25 
GeneralMy Documents icon Pin
Jonathan Gauthier5-Jan-03 8:20
memberJonathan Gauthier5-Jan-03 8:20 
GeneralExplorerListView Pin
Jonathan Gauthier4-Jan-03 8:03
memberJonathan Gauthier4-Jan-03 8:03 
GeneralRe: ExplorerListView Pin
Jonathan Gauthier4-Jan-03 8:06
memberJonathan Gauthier4-Jan-03 8:06 
GeneralRe: ExplorerListView Pin
Furty4-Jan-03 12:17
memberFurty4-Jan-03 12:17 
GeneralRe: ExplorerListView Pin
Jonathan Gauthier5-Jan-03 4:49
memberJonathan Gauthier5-Jan-03 4:49 
GeneralRe: ExplorerListView Pin
Furty5-Jan-03 18:51
memberFurty5-Jan-03 18:51 
Questionhow can I write right to left treeview? Pin
shr27-Oct-02 22:30
membershr27-Oct-02 22:30 
AnswerRe: how can I write right to left treeview? Pin
Srinivasa Raghavan28-Oct-02 1:38
memberSrinivasa Raghavan28-Oct-02 1:38 
QuestionWhy not BrowseForFolder? Pin
Heath Stewart26-Oct-02 20:11
protectorHeath Stewart26-Oct-02 20:11 
AnswerRe: Why not BrowseForFolder? Pin
Furty27-Oct-02 13:17
memberFurty27-Oct-02 13:17 
QuestionInterop.Shell32.dll...where did it come from? Pin
Jon Rista18-Oct-02 12:41
memberJon Rista18-Oct-02 12:41 
AnswerRe: Interop.Shell32.dll...where did it come from? Pin
Furty19-Oct-02 12:58
memberFurty19-Oct-02 12:58 
GeneralRe: Interop.Shell32.dll...where did it come from? Pin
Jon Rista20-Oct-02 13:04
memberJon Rista20-Oct-02 13:04 
GeneralRe: Interop.Shell32.dll...where did it come from? Pin
Furty20-Oct-02 13:54
memberFurty20-Oct-02 13:54 

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 | Cookies | Terms of Use | Mobile
Web02 | 2.8.181207.3 | Last Updated 26 Oct 2002
Article Copyright 2002 by Furty
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid