void lv_files_DragDrop(object sender, DragEventArgs e) { //Element Roll - Helper Zero dragHelper = new DragHelper(); //The item on which the draggable item was dropped Point clPoint = lv_files.PointToClient(new Point(e.X, e.Y)); ListViewItem destItem = lv_files.GetItemAt(clPoint.X, clPoint.Y); if (destItem != null) { //Check if it is a directory DirectoryInfo destDirectory = destItem.Tag as DirectoryInfo; if (destDirectory == null) { return; } else { //Is this the same directory? ListViewItem tempLvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); FileSystemInfo tempFsi = (FileSystemInfo)tempLvi.Tag; DirectoryInfo tempDi = tempFsi as DirectoryInfo; if (tempDi != null) { if (tempDi == destDirectory) { return; } } } //Moving an object to the directory ListViewItem srcItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); FileSystemInfo srcFileSystemItem = srcItem.Tag as FileSystemInfo; //New name newPath = Path.Combine(destDirectory.FullName, srcFileSystemItem.Name); if (MoveFileObject(srcFileSystemItem, newPath)) { //Refresh list if (SetFileSystemItems(tsl_path.Text)) { ShowFileSystemItems(); } //Refresh tree tv_files.SelectedNode.Collapse(); tv_files.SelectedNode.Expand(); } } }
void lv_files_DragDrop(object sender, DragEventArgs e) { //Бросок элемента - обнуление хелпера dragHelper = new DragHelper(); //Элемент на котором бросили перетаскиваемый элемент Point clPoint = lv_files.PointToClient(new Point(e.X, e.Y)); ListViewItem destItem = lv_files.GetItemAt(clPoint.X, clPoint.Y); if (destItem != null) { //Проверка, каталог ли это DirectoryInfo destDirectory = destItem.Tag as DirectoryInfo; if (destDirectory == null) { return; } else { //Не тот же ли это каталог ListViewItem tempLvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); FileSystemInfo tempFsi = (FileSystemInfo)tempLvi.Tag; DirectoryInfo tempDi = tempFsi as DirectoryInfo; if (tempDi != null) { if (tempDi == destDirectory) { return; } } } //Перемещаем объект в каталог ListViewItem srcItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); FileSystemInfo srcFileSystemItem = srcItem.Tag as FileSystemInfo; //Новый имя string newPath = Path.Combine(destDirectory.FullName, srcFileSystemItem.Name); if (MoveFileObject(srcFileSystemItem, newPath)) { //Обновить список if (SetFileSystemItems(tsl_path.Text)) { ShowFileSystemItems(); } //Обновить дерево tv_files.SelectedNode.Collapse(); tv_files.SelectedNode.Expand(); } } }