Click here to Skip to main content
6,595,854 members and growing! (18,589 online)
Email Password   helpLost your password?
Desktop Development » Tree Controls » TreeView Controls     Intermediate

FolderTreeView Control

By Furty

A simple explorer-like FolderTreeView control for C#
C#, Windows, .NET 1.0, Dev
Posted:1 Oct 2002
Updated:25 Oct 2002
Views:208,051
Bookmarked:110 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
37 votes for this article.
Popularity: 6.88 Rating: 4.39 out of 5

1
2 votes, 6.7%
2

3
4 votes, 13.3%
4
24 votes, 80.0%
5

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


Member
Furty will code for food.
Occupation: Web Developer
Location: Thailand Thailand

Other popular Tree Controls articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 105 (Total in Forum: 105) (Refresh)FirstPrevNext
GeneralNot able to see Entire Network in My Network Places Pinmemberremane3:34 24 May '07  
GeneralCompiling on Vista, executing on XP - error Pinmembersplattne24:55 15 Mar '07  
QuestionRe: Compiling on Vista, executing on XP - error PinmemberDynamite Jones6:37 27 Jul '07  
AnswerWhy are you Developing on Vista!? Pinmemberredfish3415:05 11 Oct '07  
GeneralRe: Why are you Developing on Vista!? Pinmemberdatacore22:22 29 Oct '08  
QuestionHow to remove the A: drive(diskette) from the tree? Pinmemberrytek905:47 9 Feb '07  
QuestionConnection to Live ID? PinmemberSeikilos10:57 11 Jan '07  
AnswerRe: Connection to Live ID? PinmemberSeikilos8:44 15 Jan '07  
QuestionHourglass Cursor in ExpandBranch Pinmembergoondoo2713:20 17 Nov '06  
AnswerRe: Hourglass Cursor in ExpandBranch Pinmembergoondoo277:08 20 Nov '06  
GeneralHow To Remove Network Neighbourhood, Internet Explorer and Recyle Bin ? Pinmemberscorpion_pgm823:22 30 Aug '06  
GeneralList All Computers in the network PinmemberShailesh Halankar0:35 29 May '06  
GeneralRe: List All Computers in the network Pinmemberdatacore21:58 22 Jun '06  
QuestionProblem with icons colors PinmemberGalanty0:43 23 Mar '06  
AnswerRe: Problem with icons colors Pinmembersir_mad1:15 23 Mar '06  
GeneralRe: Problem with icons colors PinmemberGalanty9:21 24 Mar '06  
GeneralDrillToFolder and unc-path Pinmembertabor256:29 2 Mar '06  
GeneralPay attention to shell extensions PinmemberLiviu5:10 7 Feb '06  
QuestionRe: Pay attention to shell extensions Pinmembersir_mad5:53 22 Mar '06  
GeneralWhat about the hidden directory ? Pinmemberbilb0t4:22 1 Feb '06  
GeneralExcellent Pinmember-Dy11:25 24 Jan '06  
GeneralPerformance and network neighbourhood Pinmemberrubberring11:32 8 Nov '05  
GeneralRe: Performance and network neighbourhood Pinmemberdario778:06 11 Jan '06  
QuestionControl in Designer with DLL Compilation Pinmemberakiriwas18:13 8 Oct '05  
AnswerRe: Control in Designer with DLL Compilation PinmemberGav_Roberts2k54:03 18 Oct '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 Oct 2002
Editor: Chris Maunder
Copyright 2002 by Furty
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project