//filling tree view private void BeforeFormLoaded() { itemsList.Clear(); foreach (var item in sysDrive.GetDrives) { itemsList.Add(item.Name); TreeNode node = this.treeView1.Nodes[0].Nodes.Add(item.Name); //if current drive is floppy if (item.DriveType.ToString() == DriveType.Removable.ToString()) { node.ImageIndex = node.SelectedImageIndex = 1; } //if current drive is fixed if (item.DriveType.ToString() == DriveType.Fixed.ToString()) { node.ImageIndex = node.SelectedImageIndex = 2; } //if current drive is cd if (item.DriveType.ToString() == DriveType.CDRom.ToString()) { node.ImageIndex = node.SelectedImageIndex = 3; } //if current drive is ready - filling it by their folders if (item.IsReady) { driveFolders = new GetFolders(item.ToString()); foreach (var folders in driveFolders.GetDirectories) { TreeNode nodes = this.treeView1.Nodes[0].Nodes[node.Index].Nodes.Add(folders.Name); nodes.ImageIndex = nodes.SelectedImageIndex = 4; } } } }
//filling items into Explorer box private void FillingItems(string newPath = "") { fileImages = new ImageList(); folderImages = new ImageList(); string newFoldersPath = ""; try { itemsList.Clear(); this.ExplorerBox.Clear(); //get main node in the tree view int par = this.treeView1.Nodes[0].FullPath.Length + 1; //get full path of current item string treePath = this.treeView1.SelectedNode.FullPath.ToString(); if (newPath == "") { //generate new path from tree view for select folders and subfolders into explorer bar newFoldersPath = treePath.Substring(par); } else { //use newPath for work with items in current drive/folder/subfolder/... newFoldersPath = newPath; } driveFolders = new GetFolders(newFoldersPath); foreach (var item in driveFolders.GetDirectories) { itemsList.Add(item.FullName); this.ExplorerBox.Items.Add(item.Name, this.ExplorerImageList.Images.Count - 1); } foldersFile = new GetFiles(newFoldersPath); foreach (var filesItem in foldersFile.GetAllFiles) { itemsList.Add(filesItem.FullName); fileImages.Images.Add(System.Drawing.Icon.ExtractAssociatedIcon(filesItem.FullName)); this.ExplorerBox.Items.Add(filesItem.Name, fileImages.Images.Count - 1); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }