private void refreshChild() { this.unloadChild(); DirectoryInfo d = new DirectoryInfo(path); if (!d.Exists) { return; } try { string[] arr_dir = Directory.GetDirectories(path); for (int i = 0; i < arr_dir.Length; i++) { DirTreeViewItem child_tvi = new DirTreeViewItem(this, arr_dir[i]); } } catch (Exception e) { Console.WriteLine("GetDirectories() = " + e.Message); Console.WriteLine(path); Console.WriteLine(); DirTreeViewItem parent_tvi = this.Parent as DirTreeViewItem; if (parent_tvi == null) { return; } parent_tvi.Items.Remove(this); } }
void curPathOpen() { string path = AppDomain.CurrentDomain.BaseDirectory; string[] split = path.Split('\\'); DirTreeViewItem cur_tvi = root_tree; DirTreeViewItem last_tvi = cur_tvi; for (int i = 1; i < split.Length; i++) { if (cur_tvi == null) { break; } for (int j = 0; j < cur_tvi.Items.Count; j++) { DirTreeViewItem tvi = cur_tvi.Items[j] as DirTreeViewItem; if (tvi == null) { continue; } if (tvi.Header.ToString() == split[i]) { tvi.IsExpanded = true; cur_tvi = tvi; last_tvi = cur_tvi; break; } } } last_tvi.IsSelected = true; }
public void refreshListView_dir(DirTreeViewItem tvi) { clearListView_dir(); for (int i = 0; i < tvi.Items.Count; i++) { DirTreeViewItem child_tvi = tvi.Items[i] as DirTreeViewItem; if (child_tvi == null) { continue; } listView_dir.Items.Add(new MyListItem() { Type = "dir", Name = child_tvi.Header.ToString() }); } string[] files = DirTreeViewItem.loadFile(tvi.path); if (files == null) { return; } for (int i = 0; i < files.Length; i++) { string[] split = files[i].Split('\\'); listView_dir.Items.Add(new MyListItem() { Type = "file", Name = split[split.Length - 1] }); } }
private DirTreeViewItem(DirTreeViewItem tvi_parent, string _path) { path = _path; string[] split = _path.Split('\\'); this.Header = split[split.Length - 1]; tvi_parent.Items.Add(this); }
void createDirTree() { string path = Directory.GetDirectoryRoot(AppDomain.CurrentDomain.BaseDirectory); //string path = AppDomain.CurrentDomain.BaseDirectory; root_tree = new DirTreeViewItem(path); treeView_dir.Items.Add(root_tree); curPathOpen(); }
private void unloadGrandChild() { for (int i = 0; i < this.Items.Count; i++) { DirTreeViewItem tvi_child = this.Items[i] as DirTreeViewItem; if (tvi_child == null) { continue; } tvi_child.unloadChild(); } }