void sortInsert(ObservableCollection <FolderMap> coll, FolderMap pice) { if (coll.Count == 0) { coll.Add(pice); //空的直接插 } else { int i = 0; while (true) { if (i >= coll.Count) { coll.Add(pice); //最后了 break; } if (coll[i].DisplayName.CompareTo(pice.DisplayName) > 0) { coll.Insert(i, pice); break; } i++; } } }
private string nodePath_before; //重复选择相同文件夹,不重新执行判断用 private void treeView_folder_MouseDoubleClick(object sender, MouseButtonEventArgs e) { FolderMap folderMapTemp = (FolderMap)this.treeView_folder.SelectedItem; String path = folderMapTemp.FullPath; if (path == "" || !Directory.Exists(path) || path == nodePath_before) { return; } nodePath_before = path; treeView1_draw(path); }
void treeView_Display(object a) { if (!Directory.Exists(w2_folderTo)) { return; } if (itemList.Count == 0) { FolderMap node_age = new FolderMap("年龄单位", @"\img\1.ico", ""); FolderMap node_month = new FolderMap("年月单位", @"\img\1.ico", ""); FolderMap node_other = new FolderMap("其他", @"\img\1.ico", ""); itemList.Add(node_age); itemList.Add(node_month); itemList.Add(node_other); } else { //itemList.Clear(); itemList[0].Children.Clear(); itemList[1].Children.Clear(); itemList[2].Children.Clear(); } DirectoryInfo TheFolder = new DirectoryInfo(w2_folderTo); string[] fileList; foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories()) { fileList = Directory.GetFiles(NextFolder.FullName, "*.*", SearchOption.TopDirectoryOnly); int okFileCount = 0; foreach (string fileCheck in fileList) { if (isRightImg(fileCheck)) { okFileCount++; } } FolderMap subNode_temp = new FolderMap(NextFolder.Name + " (" + okFileCount + ")", @"\img\2.ico", NextFolder.FullName); if (NextFolder.Name.StartsWith("年龄_")) { sortInsert(itemList[0].Children, subNode_temp); } else if (NextFolder.Name.StartsWith("年月_")) { sortInsert(itemList[1].Children, subNode_temp); } else { sortInsert(itemList[2].Children, subNode_temp); } } //按钮非活性 button_folder_from.IsEnabled = true; button_folder_to.IsEnabled = true; textBox_folder_from.IsEnabled = true; textBox_folder_to.IsEnabled = true; radio_month.IsEnabled = true; radio_age.IsEnabled = true; button_start.IsEnabled = true; }