Following my scenario.
I got an Application which loads a Filestructure (Folders, Files) from a Database into a WPF ListView. Now I'd like to grab a file from this ListView, drag it over my Desktop (or some open explorer window) and drop it there. Basic Drag and Drop, nothing fancy. This sounds like a "standard" function for a windows application - but google won't help.
So how can I achieve this? Interops?
Thanks
Edit: Thanks for the solution, I still had to do some googling. Here's my complete solution.
In File Explorer, click any file or folder and hold the left button on your mouse. Then, press the Esc key. Now, try dragging and dropping again.
Create shortcuts on your desktop by single click any icon or program file you want to create a shortcut of so it's highlighted. Once selected, click-and-hold the right mouse button, and drag that file to the desktop. When letting go of the mouse button, you have an option to Create a shortcut here.
When drag and drop does not work, left-click a file in File Explorer and keep the left click mouse button pressed. While the left click button is held down, press the Escape key on your keyboard once. Then, release the left-click mouse button. Finally, try to drag and drop again.
You can also use any of the keyboard shortcuts below to temporarily change the default drag and drop action for this instance. Press and hold the Ctrl key while you drag and drop to always copy. Press and hold the Shift key while you drag and drop to always move.
DragDrop.DoDragDrop
can do this as long as you pass it an appropriate DataObject
.
First copy the files somewhere. You can use System.IO.Path.GetTempPath()
if you don't have anywhere better.
Next create a string array containing the full paths to the files and do the following:
string[] paths = ...; DragDrop.DoDragDrop(this, new DataObject(DataFormats.FileDrop, paths), DragDropEffects.Copy);
It is actually possible to do this without pre-copying the files but that gets into some complicated IDataObject interactions, so unless your files are potentially very large and aren't already in the filesystem I would try this method first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With