|
-
October 6th, 2006, 08:51 PM
#1
File Explorer - Tree View Style
Hi,
I have the following code (at bottom of thread). All works fine, but it takes about 26 seconds to run through.
The function 'FillDirectoryNodes' is reentrant in order to populate the treeview with all directories on the HDD.
My question is, how can I speed this up?
Also, which is the part that takes the longest? Creating the treeview node, getting the directory info, etc...?
Thanks.
Code:
public partial class FileExplorer
{
public FileExplorer()
{
}
public void BuildFileExplorerTreeView(TreeView fe)
{
/* Clear the treeview control */
fe.Nodes.Clear();
/* Search the system for storage drives */
DriveInfo[] allDrives = DriveInfo.GetDrives();
/* For each drive, fill it's files and folders in the treeview */
foreach (DriveInfo currentDrv in allDrives)
{
if (currentDrv.DriveType == DriveType.Fixed)
{
TreeNode node = new TreeNode();
node.Text = currentDrv.Name.ToString();
fe.Nodes.Add(node);
FillDirectoryNodes(currentDrv.Name.ToString(), node);
}
}
}
private void FillDirectoryNodes(string drv, TreeNode parentNode)
{
DirectoryInfo dirInfo = new DirectoryInfo(drv);
try
{
if (dirInfo.Exists)
{
foreach (DirectoryInfo subDirInfo in dirInfo.GetDirectories())
{
if (subDirInfo.Exists)
{
TreeNode node = new TreeNode();
node.Text = subDirInfo.Name;
parentNode.Nodes.Add(node);
FillDirectoryNodes(node.FullPath, node);
}
else
{
return;
}
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
}
Regards,
Big Winston
-
October 6th, 2006, 09:26 PM
#2
Re: File Explorer - Tree View Style
 Originally Posted by BigWinston
My question is, how can I speed this up?
Don't load the complete drive. Load one 'level' at the time.
Also, which is the part that takes the longest? Creating the treeview node, getting the directory info, etc...?
Harddrives etc. are still not that quick, neither are 'massive' GUI oprerations.
Before you do alot of GUI updating (adding nodes, repositioning controls etc.) you should stop rendering; SuspendLayout. Then when you're don't you call ResumeLayout to make the control(s) update/render themselves.
- petter
-
October 9th, 2006, 06:52 AM
#3
Re: File Explorer - Tree View Style
 Originally Posted by wildfrog
Don't load the complete drive. Load one 'level' at the time.
Yeah, definitely do this. Just load up the information when the user requests it, you can do this in the BeforeExpand event of your treeview...
If it helped, then please rate the post by clicking "Rate this post"!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|