private void toolStripButton_Up_Click(object sender, EventArgs e) { try { string path = currentPath; if (path != "") { if (path.LastIndexOf(":\\") != path.Length - 2 && path.LastIndexOf("\\") == path.Length - 1) { path = path.Remove(path.Length - 1); } string parentDir = TreeListView.GetPathDir(path); toolStripComboBox_Path.Text = parentDir; currentPath = parentDir; TreeListView.ShowContent(listView1, parentDir); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void listView1_AfterLabelEdit(object sender, LabelEditEventArgs e) { try { if (isRenaming) { ListViewItem item = listView1.FocusedItem; string path = item.SubItems[4].Text; if (e.Label == null) { return; } FileInfo fi = new FileInfo(path); if (fi.Exists) { Microsoft.VisualBasic.FileIO.FileSystem.RenameFile(path, e.Label); string pathFolder = TreeListView.GetPathDir(path); TreeListView.ShowContent(listView1, pathFolder); } else { Microsoft.VisualBasic.FileIO.FileSystem.RenameDirectory(path, e.Label); string pathFolder = TreeListView.GetPathDir(path); TreeListView.ShowContent(listView1, pathFolder); } e.CancelEdit = true; isRenaming = false; } } catch (IOException) { MessageBox.Show("File hoặc thư mục đã tồn tại"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Form1_Load(object sender, EventArgs e) { TreeListView.CreateTreeView(this.treeView1); toolStripComboBox_Path.Width = this.Width - 120; }
private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { try { string pathSource, pathDest; if (isListView) { if (isFolder) { pathSource = pathFolder; pathDest = currentPath; } else { pathSource = pathFile; pathDest = currentPath + itemPaste.Text; } } else { pathSource = pathNode; pathDest = currentPath; } if (isCopying) { if (isFolder) { Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(pathSource, pathDest); } else { Microsoft.VisualBasic.FileIO.FileSystem.CopyFile(pathSource, pathDest); } isCopying = false; } if (isCutting) { if (isFolder) { Microsoft.VisualBasic.FileIO.FileSystem.MoveDirectory(pathSource, pathDest); } else { Microsoft.VisualBasic.FileIO.FileSystem.MoveFile(pathSource, pathDest); } isCutting = false; } string strPath; if (!isFolder) { strPath = TreeListView.GetPathDir(pathDest); } else { strPath = pathDest; } //Refresh TreeListView.ShowContent(listView1, strPath); pasteToolStripMenuItem.Enabled = false; toolStripButton_Paste.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }