Grant
Grant

Reputation: 11356

c# dragdrop from listview control

i have a c# winform app that contains a listview control. i would like to be able to drag items from the listview onto the desktop. does any one know how to do this?

I am vaguely familiar with the dodragdrop() method but not sure of the proper implementation.

Ta!

Upvotes: 4

Views: 1938

Answers (1)

Lloyd Powell
Lloyd Powell

Reputation: 18760

If you want to drag from your list view to the desktop, call DoDragDrop and create a new DataObject in the format of a FileDrop. You will need to create a temporary file to set as the file you would like to copy.

string MyFilePath = @"C:\Documents and Settings\All Users\Temp\TempFile.txt";

listView.DoDragDrop(new DataObject(DataFormats.FileDrop, MyFilePath) , DragDropEffects.Copy);

This will take the path of the temp file that you will have created and create a File Drop object, so that the desktop can recognise it and allow the copy.

Upvotes: 7

Related Questions