Reputation: 69
Im using C# 2.0 and i have created an explorer tree that i can drag information from into a windows form. right now, when i drag from the treeview that im using, it performs DoDragDrop(selectedpath, DragDropEffects.Copy);
When i catch the event in my mainform, it is listed as a string. I am able to make this work but i want it to perform the same way that it does if i were to drag a file from my windows explorer window which is as follows
Array name = (Array)e.Data.GetData(DataFormats.FileDrop);
// Ensure that the list item index is contained in the data.
if (e.Data.GetDataPresent(typeof(System.String)))
{
Object item = (object)e.Data.GetData(typeof(System.String));
// Perform drag-and-drop, depending upon the effect.
if (e.Effect == DragDropEffects.Copy ||
e.Effect == DragDropEffects.Move)
{
//// Insert the item.
//if (indexOfItemUnderMouseToDrop != ListBox.NoMatches)
// ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item);
//else
// ListDragTarget.Items.Add(item);
}
}
i have tried to do DoDragDrop(new DataObject(selectedfile),DragDropEffects.Copy) but that doesnt work.
Upvotes: 1
Views: 2841
Reputation: 16687
DoDragDrop
and DragDropEffects.Copy
will not take action on your drive, not unless you tell them to. What DragDropEffects.Copy
does is actually copy the object in the program, not the file itself.
See the documentation on DragDropEffects
.
You'll need to manage the OnDragDrop
event and use a copy function like File.Copy
Upvotes: 1