Hi well i made my first try to make a file browser but its SLOW it might be the logic im using...
is there any faster better way to make this work? would be greatfull for any help!!!
here is the code i wrote:
is there any faster better way to make this work? would be greatfull for any help!!!
here is the code i wrote:
Code:
private void Form1_Load(object sender, EventArgs e)
{
AddDrivers(DrivertreeView);
}
private void AddDrivers(TreeView TreeViewControl)
{
DriveInfo[] DriverInfos = DriveInfo.GetDrives();
foreach (DriveInfo Driveinfo in DriverInfos)
{
if (Driveinfo.Name != @"A:\")
{
Icon i = ShellIcon.GetSmallIcon(Driveinfo.Name);
SmallIconimageList.Images.Add(Driveinfo.Name, i);
TreeNode node = TreeViewControl.Nodes.Add(Driveinfo.Name, Driveinfo.Name, Driveinfo.Name, Driveinfo.Name);
DirectoryInfo Directoryinfo = new DirectoryInfo(Driveinfo.Name);
try
{
AddFolders(TreeViewControl, Directoryinfo, node);
}
catch (Exception E)
{
Trace.WriteLine(E.Message);
}
}
}
}
private void AddFolders(TreeView TreeViewControl, DirectoryInfo directory,TreeNode node)
{
DirectoryInfo[] DirectoryInfos;
try
{
DirectoryInfos = directory.GetDirectories();
}
catch(Exception)
{
return;
}
foreach (DirectoryInfo DI in DirectoryInfos)
{
Trace.WriteLine(DI.FullName);
Icon i = ShellIcon.GetSmallIcon(DI.FullName);
SmallIconimageList.Images.Add(DI.FullName, i);
node.Nodes.Add(DI.Name, DI.Name, DI.FullName, DI.FullName);
}
}
private void AddFiles(ListView listView,DirectoryInfo directory)
{
listView.Items.Clear();
FileInfo[] Files = directory.GetFiles();
foreach (FileInfo file in Files)
{
Icon i = ShellIcon.GetSmallIcon(file.FullName);
SmallIconimageList.Images.Add(file.FullName, i);
i = ShellIcon.GetLargeIcon(file.FullName);
LargeIconimageList.Images.Add(file.FullName, i);
listView.Items.Add(file.Name, file.FullName);
}
}
private void DrivertreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
foreach (TreeNode node in e.Node.Nodes)
{
Trace.WriteLine(node.FullPath);
AddFolders(DrivertreeView, new DirectoryInfo(node.FullPath), node);
}
}
private void DrivertreeView_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
AddFiles(FileslistView, new DirectoryInfo(e.Node.FullPath));
}
Attachments
Last edited by a moderator: