Click here to Skip to main content
Click here to Skip to main content

Enhanced BrowseForFolder styled TreeView

By , 7 Mar 2004
 

Introduction

This tree view control gives you the ability to control which drive types are displayed to let the user choose directories. A possible scenario is to show only local drives, because your Application scan the selected directories and fill a database with the generated meta data, and it makes no sense to allow directories from removable drives.

Design

Introduction

This release has a new design which is based on a tree view which aggregates a tree view data provider interface (Strategy pattern). The goal of the new design is to provide an easy way to extend or add data providers without changing a single line of tree view code. Basically the tree view interface will not change so far, but the data providers will change their behavior and features.

TreeViewFolderBrowser class defines the following core requirements

  • DriveTypes
  • RootFolder
  • CheckboxBehaviorMode

and is responsible to manage the checkboxes and the internal selected directories list.

ITreeViewFolderBrowserDataProvider is used by a TreeViewFolderBrowser instance and is responsible to
  • retrieve the computer drives and directories
  • Imagelist which is used to assign images to the nodes created by this instance
  • ContextMenu

and can provide custom features and behavior to extend the TreeViewFolderBrowser class.

TreeViewFolderBrowser

You can specify the drive types through a public instance property on the control. The enumeration can be treated as a bit field, that is, a set of flags.

Member Name Description
NoRootDirectory NoRootDirectory
RemovableDisk Drive has removable media. This includes all floppy drives and many other varieties of storage devices.
LocalDisk Drive has fixed (nonremovable) media. This includes all hard drives, including hard drives that are removable.
NetworkDrive Network drives. This includes drives shared anywhere on a network.
CompactDisc Drive is a CD-ROM. No distinction is made between read-only and read/write CD-ROM drives.
RAMDisk Drive is a block of Random Access Memory (RAM) on the local computer that behaves like a disk drive.

The different CheckboxBehaviorMode indicates whether check boxes are displayed next to the tree nodes in the tree view control and how the tree view handle related events. The main difference between SingleChecked and RecursiveChecked behavior, lies in the fact that the user can't unselect sub folders of a checked folder in RecursiveChecked mode.

Member Name Description
None No check boxes are displayed next to the tree nodes in the tree view control.
SingleChecked Check boxes are displayed next to the tree nodes in the tree view control. The user can check directories.
RecursiveChecked Check boxes are displayed next to the tree nodes in the tree view control. The user can check directories, the subdirectories are checked recursive.

The root folder property let you specify where the browsing starts from. Root folder values are defined by System.Environment.SpecialFolder.

Member Name Description
Desktop The tree view control shows a virtual desktop root node. Personal node points to the user my files folder. The MyComputer node shows the specified drive types.
MyComputer The tree view control shows the specified drive types on the root.
All other values from System.Environment.SpecialFolder The tree view control shows the specified root folder, the drive types are ignored.

The combination of DriveType, CheckboxBehaviorModes and SpecialFolder enumeration values gives you the ability to control how the tree view display it's content and behaves when you select a directory.

DataProvider

Data providers are the workers behind the TreeViewFolderBrowser which controls them. By implementing the ITreeViewFolderBrowserDataProvider interface, you will have full control over the core processes like retrieving data, assign images to the nodes and provide custom ContextMenu items for each node. But you don't have to care about checkboxes, load on demand, find node at position if the user request the ContextMenu, you will be hooked if it's time to take some action on it. The only thing you must respect is the core functionality (DriveTypes and RootFolder) implemented by the TreeViewFolderBrowser.

To provide clean access to the handled TreeViewFolderBrowser class instance every method on the data provider interface provides an TreeViewFolderBrowserHelper class instance which lets you create nodes and give you access to the TreeViewFolderBrowser instance.

Please take a look at the two delivered standard implementations which can be found in the Raccoom.TreeViewFolderBrowser.DataProviders project.

Key features

TreeViewFolderBrowser

  • Different build in CheckboxBehaviorModes.
  • Step by step population for subdirectories.
  • Parent nodes are bold if there are selected subfolders, this helps to find selected directories in large structures.

TreeViewFolderBrowserDataProvider

  • Drive enumeration through strong typed Win32_Logicaldisk WMI class.
  • Shell32 ImageList used to retrieve Icons.
  • System.IO namespace used to retrieve directories
  • Respects the code access security features from .NET

TreeViewFolderBrowserDataProviderShell32

Inherit from TreeViewFolderBrowserDataProvider

  • Drive and directory enumeration through Shell32 interop against strong typed Win32_Logicaldisk WMI class drive types. (Does not respect .NET code access security)
  • Supports Shell32 virtual folders (non file system folders)
  • Shell32 ImageList used to retrieve Icons.
  • Functional context menu items for each shell object.
  • Tested against WinXP and Win2000.

Using the code

Before you begin make sure your project has a valid reference to the Raccoom.TreeViewFolderBrowser.dll. Go to the Toolbox window, right-click and select Customize Toolbox from the context menu. In the Customize Toolbox dialog go to the .NET Framework Components tab and select the Raccoom.TreeViewFolderBrowser.dll assembly that you just compiled. Now drop the TreeViewFolderBrowser control to your form.

This example assumes that you have created an instance of a TreeViewFolderBrowser control on a Form.

Fill data

// set standard data provider
this.myTreeView.DataSource = 
 new Raccoom.Windows.Forms.TreeViewFolderBrowserDataProvider();
// set drive types
this.myTreeView.DriveTypes
= DriveTypes.LocalDisk | DriveTypes.NetworkDrive | 
 DriveTypes.RemovableDisk |
 DriveTypes.CompactDisc;
// set checkbox behavior mode
this.myTreeView.CheckboxBehaviorMode= CheckboxBehaviorMode.SingleChecked;
// fill root level
this.myTreeView.Populate();
Event Handling
private void treeView_SelectedDirectoriesChanged(
 object sender, Raccoom.Windows.Forms.SelectedDirectoriesChangedEventArgse)
{
// determine the path which is currently added (checked) 
// or removed (unchecked)
this.statusBar1.Text = e.Path + " is now " + e.CheckState.ToString();
// display all selected path's in a listbox
this.listBox1.Items.Clear();
foreach(string s in myTreeView.SelectedDirectories)
{
this.listBox1.Items.Add(s);
} 
}

Conclusions

This control display drive types and folders, so far so good. Removable disk's can change their medium and folders can change (new folder, delete folder) during run time, the control does not care about that.

Links

History

  • 04.03.2004 Major design changes
  • 08.02.2004 Major update
  • 02.07.2003 final release

Have phun...

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

About the Author

Chris Richner
Software Developer (Senior) Zeit AG
Switzerland Switzerland
Member
Biography
  • 1996 - 1998 PC Board PPL, HTML, DHTML, Javascript and ASP
  • 1999 - 2001 coding Centura against Sql Database (Centura,MSSQL,Oracle)
  • 2002 - 2004 C# Windows Forms
  • 2005 - 2006 C# ASP.NET, Windows Forms
  • 2006 - 2009 C#, WCF, WF, WPF
  • 2010 - 2012 C#, Dynamics CRM, Sharepoint, Silverlight
  • 2013 - now C#, WCF DS (OData), WF, WPF
Interests
  • family & friends
  • chilaxing ,)
  • coding

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralAwesome Articlememberashishgupta12122 Mar '13 - 8:26 
I very lucky to find this article.
GeneralRe: Awesome ArticlememberChris Richner3 Mar '13 - 2:09 
You're welcome Big Grin | :-D

BugException fix.memberKoson26 Jun '12 - 0:23 
Hi, I've found some bug on your code in the file TreeViewFolderBrowser.cs.
 
In the function
public virtual void RemoveDummyNode()
and line number 866.
It should be "&&" instead of "&".

864          public virtual void RemoveDummyNode()
865          {
866              if ((Nodes.Count == 1 ) && (Nodes[0].Text == "@@Dummy@@"))
867              {
868                  Nodes[0].Remove();
869              }
870          } 
 
It's a cause of exception
"A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Windows.Forms.dll".
GeneralRe: Exception fix.memberChris Richner23 Jul '12 - 23:31 
Hi

Thanks for sharing your fix! Big Grin | :-D

SuggestionSorting of the subdirsmemberm_kuhn11 Dec '11 - 2:16 
Hello,
I would like to have the directories sorted.
I used at my code the follwoing extension to Yours:
private DirectoryInfo[] SortDirArray( DirectoryInfo[] unsorted )
{
    try
    {
        Array.Sort<DirectoryInfo>( unsorted, new
            Comparison<DirectoryInfo>( delegate( DirectoryInfo d1, DirectoryInfo d2 )
                  {
                       return string.Compare( d1.Name, d2.Name );
                     } 
                  ) 
               );
    }
    catch
    {
    }
    return unsorted;
}
 
public virtual void RequestSubDirs(TreeViewFolderBrowserHelper helper, TreeNodePath parent, TreeViewCancelEventArgs e)
{
	if(parent.Path==null) return;
	//
	DirectoryInfo directory = new DirectoryInfo(parent.Path);	
	// check persmission
	new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.PathDiscovery, directory.FullName).Demand();										
	//					
	foreach( DirectoryInfo dir in SortDirArray(directory.GetDirectories()))
	{
		if ((dir.Attributes & System.IO.FileAttributes.System) == System.IO.FileAttributes.System)
		{
			continue;
		}
		if ((dir.Attributes & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden)
		{
			continue;
		}
		TreeNodePath newNode = this.CreateTreeNode(helper, dir.Name,dir.FullName,false,((helper.TreeView.CheckboxBehaviorMode != CheckboxBehaviorMode.None) && (parent.Checked)),false);
		parent.Nodes.Add(newNode);						
		//
		try
		{
			if(dir.GetDirectories().GetLength(0) > 0)
			{
				newNode.AddDummyNode();
			}
		} 
		catch{}						
	}			
}
Perhaps You can include it into Yours.
Thank You. Smile | :)
GeneralRe: Sorting of the subdirsmemberChris Richner15 Mar '12 - 0:43 
Hi
 
Thanks for sharing your extension! Big Grin | :-D

GeneralMy vote of 5memberDontSailBackwards23 Nov '11 - 10:12 
Nice!
QuestionDe-selecting Subfolders? [modified]memberMember 30938448 Jun '11 - 5:26 
when I select a folder that has subfolders it will check all the subfolders but if I click on the folder again it will NOT de-select the subfolders? Any way to fix that?

modified on Wednesday, June 8, 2011 12:08 PM

AnswerRe: De-selecting Subfolders? [modified] [modified]memberDontSailBackwards23 Nov '11 - 10:17 
This seems to work for me ... at line 581 in TreeViewFolderBrowser.cs I commented out ...
 
// is it allowed to check item ? 
//if ((this.CheckboxBehaviorMode==CheckboxBehaviorMode.RecursiveChecked) & (!check) & (e.Node.Parent!=null) 
//   && (e.Node.Parent.Checked))
//{
//   e.Cancel = true;
//   base.OnBeforeCheck(e);
//   return;
//}
 

also, to add the names of recursed folders to the list ...
 
in TreeViewFolderBrowser.cs at line 601 ... change ExchangeFoldersRec(e.Node as TreeNodePath,false); to ExchangeFoldersRec(e.Node as TreeNodePath,check);
 
Bummer is, even after I butchered this, and some other code, it generally only added 1 subfolder deep of recursion to folderlist. The caveat is that it will only recurse as deep as the tree has been expanded because it is lazy-loaded. ie - the deeper levels of the tree that have not been expanded have not been populated with any information.
 
Meddling with this code makes the folderlist worthless, out of sync with the checkboxes, unless you figure out a way to automagically recurse all the way down on a folder that has been checked.
 
As it stands, including my meddling, you can't reliably make a folderlist with each and every folder that is checked because all of the tree branches have to be expanded.
 
Still, it works as promised and this is mentioned in the article.
www.CADbloke.com
The Broadcast Systems Documentation SYSTEM
 
"The mass of men lead lives of quiet desperation"
-Zen & the Art of Motorcycle Maintenance


modified 23 Nov '11 - 23:15.

GeneralRe: De-selecting Subfolders? [modified]memberChris Richner23 Nov '11 - 23:09 
Thanks for your support!
 
Good job! Big Grin | :-D

QuestionI may seem stupid, but ..memberNigel Mackay20 Jun '10 - 21:32 
Converted, successfully, to C# 2008 Express.
 
I think because it is Express, I don't see the TreeViewFolderBrowser in my toolbox - will have to use Save as and then delete all unnecessary code.
 
Now for the stupid bit!! Having selected the folders, how to I access the files in the selected folders - want to add them to a list.
 
Thanks
Nigel
GeneralI wonder How did you add the reference named "TreeViewExplorer_Source" in Raccoom.TreeViewFolderBrowser.Demomemberic_nim15 Feb '10 - 7:18 
I'm very very new to C#.After I have study your code,I notice that It's under Raccoom.TreeViewFolderBrowser.dll. However, I don't know how did you add it to the project since it's inside the dll again, or I'm just too new for C#.
GeneralWorks on Vista, not on XPmemberscotchfaster29 Nov '09 - 18:36 
I'm using this in my .NET 2.0 project, and it works great on my Vista box.
 
However, when I give the executable to the client who is running XP, it immediately throws an exception with this text:
 
Unable to cast COM object of type 'Shell32.ShellClass' to interface type 'Shell32.IShellDispatch5'. This operation failed because the QueryInterface call on the COM component <snip> failed <snip> at Raccoom.Windows.Forms.TreeViewFolderBrowser.Populate(...
 

Any help in solving this problem would be greatly appreciated.
GeneralRe: Works on Vista, not on XPmemberChris Richner30 Nov '09 - 6:24 
I assume that the IShellDispatch5 interface is only available on vista and higher. Are you running your visual studio on a vista machine?
 
Please check out http://forum.excelprofessionals.net/framehelper.aspx?g=posts&m=12[^]
 
hope this helps...
 

GeneralRe: Works on Vista, not on XPmemberscotchfaster21 Dec '09 - 15:31 
Thanks, that did help.
 
If I build the project on XP, it works fine on both platforms. I'm using VMWare to run XP on my Windows 7 box. Thanks again!
GeneralMulti Columnsmemberddurnan22 Oct '09 - 1:36 
Has anyone added multicolumn support to include Date and Size?
GeneralContext menumemberPhazonmutant10 Aug '09 - 13:13 
I'm trying to get a context menu to show up when the user right-clicks anywhere in the control. Right now, it seems the MouseClick event fires only if the mouse is over text, but even then it doesn't display the context menu. Any tips?
GeneralRe: Context menumemberChris Richner10 Aug '09 - 20:27 
Please check out the TreeViewFolderBrowserDataProviderShell32 source code. This class shows off how to invoke a custom context menu.
 
BTW: The TreeView creates an internal context menu instance which it will route to the attached data provider when the user right clicks on a node. Caused by the hit test it just shows off if the user clicks over a node rectangle.
 
Hope this helps
 

Generalpopulate with List<string> (or StringCollection) of paths</string>memberSaso Tepina2 Apr '09 - 18:47 
I could really use something like
public virtual void Populate(List<string> path_list)
Maybe it is there, and I just didn't find it ...
 
So I put the folowing code to the form and it works well:
 
        private void fill()
        {
            tvfb.Populate();
 
            DataTable dt = Base.Select(@"SELECT * FROM CheckedFolder;"); // I save tvfb.SelectedDirectories to DB on FormClosing. You can fill the list any way you want.
            List<string> path_list = new List<string>();
            foreach (DataRow dr in dt.Rows)
                path_list.Add(dr["Path"].ToString());
 
            path_list.Sort();
            checkFolders(path_list);
        }
 
        private void checkFolders(List<string> path_list)
        {
            foreach (TreeNodePath tn in tvfb.Nodes)
            {
                foreach (string s in path_list) // if the subdir has to be checked expands the parent node
                {
                    if (tn.Path == Regex.Match(s, @"[A-Z]:\\(?=.)").Value)
                    {
                        tn.Expand();
                        break;
                    }
                }
 
                if (path_list.Contains(tn.Path))
                    tn.Checked = true;
 
                checkTreeNode(tn, path_list);
            }
        }
 
        private void checkTreeNode(TreeNodePath tnParent, List<string> path_list)
        {
            foreach (TreeNodePath tn in tnParent.Nodes)
            {
                string regex = @"[A-Z]:";
                regex += regexAddSubDir(tn); // modifies the regex depending on node depth (number of parents)
                regex += @"(?=\\)";
 
                foreach (string s in path_list) // if the subdir has to be checked expands the parent node
                {
                    if (tn.Path == Regex.Match(s, regex).Value)
                    {
                        tn.Expand();
                        break;
                    }
                }
 
                if (path_list.Contains(tn.Path))
                    tn.Checked = true;
 
                checkTreeNode(tn, path_list);
            }
        }
 
        private string regexAddSubDir(TreeNodePath tn)
        {
            string ret = "";
 
            if (tn.Parent != null) // modifies the regex depending on node depth (number of parents)
            {
                ret += @"\\([^\\]+)";
                ret += regexAddSubDir((TreeNodePath)tn.Parent);
            }
 
            return ret;
        }
 
It could also be implemented in the TreeViewFolderBrowser class, I guess.
GeneralRe: populate with List (or StringCollection) of pathsmemberChris Richner2 Apr '09 - 21:50 
Thanks for sharing...
 
By design this role is played by the SelectedDirectories list which is provided by the tree view
 
myTreeView.SelectedDirectories
 
this list serves as the data source for all the selection stuff like in your scenario.
 
Did you try this as mentionded above in first place?
 

GeneralRe: populate with List (or StringCollection) of paths [modified]memberSaso Tepina2 Apr '09 - 22:22 
So that is how it woks ...
 
tvfb.Populate();
StringCollection sc = new StringCollection();
sc.Add("C:\\Program Files");
tvfb.SelectedDirectories = sc;
 
the only difference is that it does not expand the parent nodes of checked nodes. Or is that also somewhere I did not look?
 
P.S.
Great work!
 
modified on Friday, April 3, 2009 5:13 AM

GeneralRe: populate with List (or StringCollection) of pathsmemberChris Richner2 Apr '09 - 23:21 
seems that you rather spend your time incorporating the code instead of reading the article Poke tongue | ;-P
 
just kidding... AFAIR there is a ShowFolder(string path) method.
 
I think it's not a common scenario that you expand all "selected" folders.. imagine one has 1000 selections... the time the user is waiting until everything is in place is simply too long...
 
that's the reason why the folders which have selected child folders and files have a bold font.. so the user can navigate as he likes to "some" selected folders...
 
but that's maybe just a "concept" and not a scenario every app can use...
 
maybe you just need to call ShowFolder for each selected directory in tvfb.SelectedDirectories
 
PS: Thanks.. you're welcome
 

GeneralRe: populate with List (or StringCollection) of pathsmemberSaso Tepina2 Apr '09 - 23:39 
I suspected it would be something simple.
So it was all there all the time.
 
...
 
I tried it, and ...
ShowFolder also has that bug mentioned in the other tread.
- If I set the SelectedDirectories first and then show the folders all subfolders of checked folder get the checked mark, because GetSubDirs is not called.
- If I show the folders first, then none of them gets the checked mark.
 

Maybe I should just add the GetSubDirs somewhere. I'll look into it.
 
My code works fine, because it expands the node before it is checked.
And I altered the OnBeforeCheck as described in the other tread, so it would work fine even if the nodes don't get expanded.
 
modified on Friday, April 3, 2009 5:46 AM

GeneralRe: populate with List (or StringCollection) of pathsmemberSaso Tepina3 Apr '09 - 0:35 
After some more testing I just added the following to the TreeViewFolderBrowser.cs. Works for me.
 
It does take longer to load than just setting the SelectedDirectories, but the checkmark bug just bugs me too much.
 
Thanks again for your great work!
 
/// <summary>
        /// Clears the TreeView and popluates the root level and all selected folders.
        /// </summary>
        /// <param name="path_list"></param>The paths of the folder sthat should be checked after population.
        /// <param name="expandNodes"></param>if True, expands the parent nodes of selected folders after population.
        public virtual void Populate(StringCollection path_list, bool expandNodes)
        {
            Populate();
 
            foreach (TreeNodePath tn in this.Nodes)
            {
                foreach (string s in path_list) // if the subdir has to be checked expands the parent node   
                {
                    if (tn.Path == Regex.Match(s, @"[A-Z]:\\(?=.)").Value)
                    {
                        if (expandNodes)
                            tn.Expand();
                        else
                        {
                            try { GetSubDirs(tn, new TreeViewCancelEventArgs(null, false, TreeViewAction.ByMouse)); }
                            catch { }
                        }
                        break;
                    }
                }
 
                if (path_list.Contains(tn.Path))
                    tn.Checked = true;
                checkTreeNode(tn, path_list, expandNodes);
            }
        }
 
        private void checkTreeNode(TreeNodePath tnParent, StringCollection path_list, bool expandNodes)
        {
            foreach (TreeNodePath tn in tnParent.Nodes)
            {
                string regex = @"[A-Z]:";
                regex += regexAddSubDir(tn); // modifies the regex depending on node depth (number of parents)        
                regex += @"(?=\\)"; foreach (string s in path_list) // if the subdir has to be checked expands the parent node    
                {
                    if (tn.Path == Regex.Match(s, regex).Value)
                    {
                        if (expandNodes)
                            tn.Expand();
                        else
                        {
                            try { GetSubDirs(tn, new TreeViewCancelEventArgs(null, false, TreeViewAction.ByMouse)); }
                            catch { }
                        }
                        break;
                    }
                }
 
                if (path_list.Contains(tn.Path))
                    tn.Checked = true;
 
                checkTreeNode(tn, path_list, expandNodes);
            }
        }
 
        private string regexAddSubDir(TreeNodePath tn)
        {
            string ret = ""; if (tn.Parent != null) // modifies the regex depending on node depth (number of parents)      
            { ret += @"\\([^\\]+)"; ret += regexAddSubDir((TreeNodePath)tn.Parent); }
            return ret;
        }

GeneralRe: populate with List (or StringCollection) of pathsmemberChris Richner3 Apr '09 - 5:42 
ok, I guess I'll have to crawl through all the contributed code to update my code base and release a bug fixed (and btw. tested on Windows 7 beta) version ,)
 
looks like I'll have some coding nights ahead Laugh | :laugh:
 
PS: Are you willing to get your hands on a pre released version?
 

GeneralRe: populate with List (or StringCollection) of pathsmemberSaso Tepina3 Apr '09 - 6:31 
Thank you, I will be glad to do some beta testing.
As for OS, I'm just sticking with XP for now. So no help for Vista or W7 from me.
GeneralRe: populate with List (or StringCollection) of pathsmemberChris Richner5 Apr '09 - 21:21 
that's fine.. so the major OS Versions (XP, Vista and Windows 7) are concerned Poke tongue | ;-P
 

GeneralFix for a little bug (all subfolders checked if you first check and then expand)memberSaso Tepina2 Apr '09 - 16:17 
You need to scan for subfolder before you check ... put:
 
TreeNodePath node = e.Node as TreeNodePath;
            try
            {
                GetSubDirs(node, e);
            }
            catch {}
 
in OnBeforeCheck, just like in OnBeforeExpand. (Catch can stay empty, try is good enough.)
It might also help with recursive check, I didn't look into that, since I only need a sigle check.
General"Failed to get icon index" on VistamemberDenXX19 Feb '09 - 13:36 
Hello,
 
at first, thanks for te great article and control. However, i encoutered some problems running the demo on Vista. The "Failed to get icon index" assertion is shown when the control is populating. The issue is caused by the fact that your code attempts to get icon for system folders like Control panel and the fileName variable in:
SHGetFileInfo(fileName, dwAttr, ref shfi, shfiSize,((uint)(dwFlags) | (uint)iconState));
equals a string like "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
 
Have you any thoughts on how to avoid the problem?
 
I think the problem could be solved by using PIDL instead of fileName, but i have no idea how to get PIDL for the FolderItem.
GeneralRe: "Failed to get icon index" on VistamemberChris Richner19 Feb '09 - 23:03 
Hi,
 
You're welcome. I guess the code base needs a refresh that boost it from the year 2003 to 2009 where Windows 7 comes in ,)
 
If someone already fixed that part of the code please contribute.
 
Maybe you just need to look for a similiar articles here at cp and merge the SystemImageList part... at least that would be my happy guess to do it.
 

GeneralRe: "Failed to get icon index" on Vistamemberkingjotte1 Apr '09 - 22:04 
I think this is caused by the fact that ZIP archives are also marked as a folder.
 
just add a clause to ignore those (and maybe .rar also, didn't check that) and you're good to go.
 
(worked for me in any case)
GeneralVery nice workmemberimadulhaq14 Jan '09 - 2:56 
I have a question what will be your strategy to load folder containing 1 million files in it. I have seen many File Explorer controls but the all use shell and hang while loading such folder or drive.
GeneralRe: Very nice workmemberChris Richner14 Jan '09 - 7:20 
Hi imadulhaq,
 
Show me a user that wants/needs to work with a million files at one moment in time ,) If one can't create/show so much files in one folder (OS Shell) why does one want to see them at one in a custom application? Where's the use case for your question?
 

GeneralRe: Very nice workmemberimadulhaq14 Jan '09 - 18:14 
Well you are right.
I am working on a Backup application. The application facilitates user to take backup of folders/ directories of his choice. Therefore, we'll have to support files/folders in millions present in a folder/ directory as well. You are absolutely right about Shell, it hangs and very slow while enumerating large number of files.
What is your advice to handle such a situation?
GeneralRe: Very nice workmemberChris Richner15 Jan '09 - 3:45 
First I would investigate how good backup softwares today solved this kind of problem. Second I think no matter what kind of software you're writing the user will never need and wants to see thousands of files on the screen.
 
Strategies might be to create virtual groups for the files by
- file extension
- by alphabet starting letter
- by Creation Date/Week/Year or a like
 
into a virtual folder and let the user expand just that folder providing just a minimal and also workable subset of the total files.
 
Maybe you better of providing a vista like instant search where the user can search/query for the files he needs to see?
 

GeneralRemovable harddisks are displayed even when selected drivetype is LocalDiskmemberdkmittal3 Nov '08 - 20:25 
Hi
 
Removable hard disks ( USB hard disk ) are being displayed even when selected drive type is Local Disk. This problem doesn't occur with removable flash drives. Have you also faced the same issue with this application?
 
In my application code also if I query win32_logicaldisk objects, win32_logicaldisk object coresponding to removable hardisk gives drive type = 3 ( that is for local disks ) while it should give 2. For removable flash drives the drivetype value is 2 as expected. I think that is the reason for the problem.
 
Can you please let me know if you find any solution for that?
GeneralRe: Removable harddisks are displayed even when selected drivetype is LocalDiskmemberChris Richner4 Nov '08 - 5:27 
Hi,
 
I'm not aware of this issue. Maybe it's just the usb hard disk driver in use that specifies the drive type?
 
I have no idea, sorry
 

QuestionRecursive check does not workmemberdatacore29 Oct '08 - 10:01 
Hi and first: u did a realy good job Smile | :)
 
But i've a problem with the "recursive check". When I set the property: "CheckboxBehaviorMode" to "RecursiveChecked", I get the following:
 
Windows Vista
 
Standard Provider:
* First click = select's the clicked folder plus all subfolders
* Second click = deselect's all folders
* After this, next click will only select the clicked folder without subfolders... :/
 
Shell32 Provider
* Same behavior as above except, not expanded folders won't select his child's (I think it's a performance thing: You only load the childs of a folder when you click on it)
 
Windows Server 2003 & Windows XP
 
Standard Provider:
* Works, but I can't uncheck a folder under the clicked folder
 
Shell32 Provider
* Works also, but with the same Problem. Subfolders which aren't expanded won't be checked.
 
---
 
All testet with the demo version from here @codeProject. Does anyone have the same problem or maybe a easy fix?
 
thx in advance Wink | ;)
AnswerRe: Recursive check does not workmemberChris Richner30 Oct '08 - 6:25 
currently I'm trying to repro this stuff on a Windows Server 2008, no luck
 
did you work with your mouse oder the keyboard? Did you expand each level of his own or by '*' key to expand all children?
 

AnswerRe: Recursive check does not workmemberkingjotte1 Apr '09 - 22:07 
I had the same problem, spent 4 hours on it last night, and now it works Smile | :)
 
I can give you the code, but I'd like it if my name stayed attached Wink | ;)
 
Send me a mail, or just reply to this thread if you want it.
GeneralRe: Recursive check does not workmemberChris Richner2 Apr '09 - 1:31 
You're welcome to contribute your changes and I will incorporate those into the latest code base for updating the article, interested?
 
You will be named of course Wink | ;)
 

GeneralRe: Recursive check does not workmemberkingjotte2 Apr '09 - 2:26 
Off course, always glad to help.
 
What is the best way to send you the code? E-Mail?
 
I updated the project to VS 2008 also (since I don't have any other version Wink | ;) )
 
Grtz!
GeneralMapped network drivesmemberM1iS23 Sep '08 - 10:56 
Is there a trick to get mapped network drives to show up? I have DriveTypes set to All and I don't see my mapped network drivers. Could this be a Vista OS problem?
GeneralRe: Mapped network drivesmemberChris Richner27 Sep '08 - 2:37 
Hi,
 
Maybe, do you use the Shell32 Provider? Do you see the network drives in the windows explorer?
 

GeneralRe: Mapped network drivesmemberkingjotte1 Apr '09 - 22:08 
Are the drives connected?
QuestionTransparent iconsmembermaster20218 Sep '08 - 6:39 
Is possible set icons folders, files, (drivers etc...) on transparent color or other color than white. Because when I set bacground color of TreeViewFolderBrowser control on black then icons have still white color. Thank for any idea.
AnswerRe: Transparent iconsmemberChris Richner27 Sep '08 - 2:39 
Hi,
 
Never tried but does it "only" happen when you change the backcolor after the control is visible already or does it happen all the time?
 
Maybe you have to re-initialize the ShellImageList again after the back color has changed, not sure how to handle the shell image list in terms of back color.
 

GeneralRe: Transparent iconsmembermaster20228 Sep '08 - 4:14 
Hi,

Never tried but does it "only" happen when you change the backcolor after the control is visible already or does it happen all the time?

It does not matter. I try both ways.

Maybe you have to re-initialize the ShellImageList again after the back color has changed, not sure how to handle the shell image list in terms of back color.

Could you show me some example how do it?
GeneralRe: Transparent iconsmemberChris Richner28 Sep '08 - 12:28 
With "not sure how to handle" I meant I have no clue about it, sorry
 

GeneralQuestion about filesmemberclu8229 Aug '08 - 8:42 
Chris,
 
Great code. One question if I may: I would like the treeview to display normal files also. Is there a way get this functionality?
 
Thanks in advance.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 8 Mar 2004
Article Copyright 2003 by Chris Richner
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid