Drag & Drop file from listview to windows explorer?

早过忘川 提交于 2021-02-11 02:48:50

问题


I have a bunch of files listed within a listview, and I want to know is it possible to drag and drop the files to Windows Explorer? If so how? I only seem to find examples of the other way around. Thanks!


回答1:


So here's what I did.

First off, in your listview, create an event handler for ItemDrag.

Then the following..

    private void listView_ItemDrag(object sender, ItemDragEventArgs e)
    {
        List<string> selection = new List<string>();

        foreach (ListViewItem item in listView.SelectedItems)
        {
            int imgIndex = item.ImageIndex;
            selection.Add(filenames[imgIndex]);
        }

        DataObject data = new DataObject(DataFormats.FileDrop, selection.ToArray());
        DoDragDrop(data, DragDropEffects.Copy);
    }


来源:https://stackoverflow.com/questions/26660418/drag-drop-file-from-listview-to-windows-explorer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!