JLYK
JLYK

Reputation: 391

Drag & Drop file from listview to windows explorer?

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!

Upvotes: 1

Views: 2334

Answers (1)

JLYK
JLYK

Reputation: 391

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);
    }

Upvotes: 8

Related Questions