I've been having a hard time lately with implementing the drag and drop functionality outside the windows forms. I have no problem doing drag and drop within and between windows forms and from the desktop to the windows form. I have created an application where you can drag and drop any item on it. My problem is, I do not know how to implement the reverse of my application, to drag and drop from my app to the desktop or any destination outside my form. Any advise and ideas I will gratefully accept. Thank you.
we are talking about files and folders here ok :)
I don't know which control you are using; most of the .net controls have a method DoDragDrop
. Please use this method if it suits you.
private void PopulateListView()
{
string directoryPath=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
String[] files=System.IO.Directory.GetFiles(directoryPath);
if(files!=null)
{
foreach(string file in files)
{
listView1.Items.Add(new ListViewItem(file));
}
}
}
private void listView1_MouseDown(object sender, MouseEventArgs e)
{
System.Collections.Specialized.StringCollection filePath = new
System.Collections.Specialized.StringCollection();
if (listView1.SelectedItems.Count > 0)
{
filePath.Add(listView1.SelectedItems[0].Text);
DataObject dataObject = new DataObject();
dataObject.SetFileDropList(filePath);
listView1.DoDragDrop(dataObject, DragDropEffects.Copy);
}
}
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