Click here to Skip to main content
Licence 
First Posted 1 Oct 2002
Views 260,433
Downloads 1,386
Bookmarked 124 times

FolderTreeView Control

By | 25 Oct 2002 | Article
A simple explorer-like FolderTreeView control for C#

Sample Image

Introduction

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 not 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.

Usage

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 sucessful or not.

The method used to retreive 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 OS's 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.

Updates

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 - feeback on how it works with other OS's would be appreciated!

License

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

Furty

Web Developer

Thailand Thailand

Member

Furty will code for food.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNot able to see Entire Network in My Network Places Pinmemberremane2:34 24 May '07  
GeneralCompiling on Vista, executing on XP - error Pinmembersplattne23:55 15 Mar '07  
QuestionRe: Compiling on Vista, executing on XP - error PinmemberDynamite Jones5:37 27 Jul '07  
AnswerWhy are you Developing on Vista!? Pinmemberredfish3414:05 11 Oct '07  
GeneralRe: Why are you Developing on Vista!? Pinmemberdatacore21:22 29 Oct '08  
QuestionHow to remove the A: drive(diskette) from the tree? Pinmemberrytek904:47 9 Feb '07  
QuestionConnection to Live ID? PinmemberSeikilos9:57 11 Jan '07  
AnswerRe: Connection to Live ID? PinmemberSeikilos7:44 15 Jan '07  
QuestionHourglass Cursor in ExpandBranch Pinmembergoondoo2712:20 17 Nov '06  
AnswerRe: Hourglass Cursor in ExpandBranch Pinmembergoondoo276:08 20 Nov '06  
QuestionHow To Remove Network Neighbourhood, Internet Explorer and Recyle Bin ? Pinmemberscorpion_pgm822:22 30 Aug '06  
GeneralList All Computers in the network PinmemberShailesh Halankar23:35 28 May '06  
GeneralRe: List All Computers in the network Pinmemberdatacore20:58 22 Jun '06  
QuestionProblem with icons colors PinmemberGalanty23:43 22 Mar '06  
AnswerRe: Problem with icons colors Pinmembersir_mad0:15 23 Mar '06  
GeneralRe: Problem with icons colors PinmemberGalanty8:21 24 Mar '06  
AnswerRe: Problem with icons colors Pinmembernguyen_freddie17:55 17 Jan '10  
GeneralDrillToFolder and unc-path Pinmembertabor255:29 2 Mar '06  
GeneralPay attention to shell extensions PinmemberLiviu4:10 7 Feb '06  
QuestionRe: Pay attention to shell extensions Pinmembersir_mad4:53 22 Mar '06  
QuestionWhat about the hidden directory ? Pinmemberbilb0t3:22 1 Feb '06  
GeneralExcellent Pinmember-Dy10:25 24 Jan '06  
GeneralPerformance and network neighbourhood Pinmemberrubberring10:32 8 Nov '05  
GeneralRe: Performance and network neighbourhood Pinmemberdario777:06 11 Jan '06  
QuestionControl in Designer with DLL Compilation Pinmemberakiriwas17:13 8 Oct '05  
Furty,
 
I've just started doing a lot of C# .NET development and I noticed something in this project after downloading that was quite intriguing to me. You create a custom control called FolderTreeView which inherits from System.Windows.Forms.TreeView. This is great and so far nothing is a mystery. What IS a mystery to me, is that although you haven't created a seperate project and compiled this new control into a DLL, you somehow added it to the TestForm in Design view, yet I don't see how since it is not in the toolbox and there is no seperately compiled DLL for the FolderTreeView which I can add a reference to. How did you add your new control to the form visually? Thanks alot and keep up the great work.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web02 | 2.5.120529.1 | Last Updated 26 Oct 2002
Article Copyright 2002 by Furty
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid