void FolderBrowserAction() { if (fb.ShowDialog() == DialogResult.OK) { if (tv.ImageList != null) { tv.ImageList.Dispose(); } tv.Nodes.Clear(); lv.Items.Clear(); curpath = fb.SelectedPath; tstb.Text = curpath; DirectoryInfo dii = new DirectoryInfo(curpath); TreeNode tn1 = new TreeNode(dii.FullName); // Get ShellFileInfo using (CsShellFile shellFile = new CsShellFile(dii.FullName, SHGFI.ICON | SHGFI.LARGEICON | SHGFI.SYSICONINDEX)) { tn1.ImageIndex = (int)shellFile.IIcon; tn1.SelectedImageIndex = (int)shellFile.IIcon; } // SHFileInfo bs = Shell32.StrIco( dii.FullName, SHGFI.ICON|SHGFI.LARGEICON|SHGFI.SYSICONINDEX ); // User32.DestroyIcon(bs.hIcon); foreach (string s in Directory.GetDirectories(curpath)) { DirectoryInfo di = new DirectoryInfo(s); tn1.Nodes.Add(GetDirectoryRootNode(di.FullName)); } tv.Nodes.Add(tn1); tv.Sorted = true; tv.Sort(); } }
/// <summary> /// We remove all child elements from a given tree node, /// and rebuild one level of children. /// </summary> /// <remarks>Assigned: after-collapse</remarks> void TreeView_Event_AfterCollapse(object sender, TreeViewEventArgs e) { // update the current path CurPath = (e.Node.FullPath).Replace("\\\\", "\\"); // text is updated e.Node.Nodes.Clear(); DirectoryInfo selected_directory = new DirectoryInfo(CurPath); foreach (DirectoryInfo dir in selected_directory.GetDirectories()) { using (CsShellFile Ja = new CsShellFile(dir.FullName, _sys_ico_lrg)) Ja.AddChild(e.Node, dir); } }