dipique
Member
- Joined
- Oct 22, 2014
- Messages
- 7
- Programming Experience
- 1-3
I have filenames in a listbox and would like to drag an item from the listbox onto the desktop and have the file copied there. Here's the code I currently use when drag:
[XCODE] private void lstResults_MouseMove(object sender, MouseEventArgs e)
{
//If the mouse is in a draggable state and there is a selected item
if (_canDrag && (lstResults.SelectedIndex != -1))
//make sure the string refers to a real, existing file
if (File.Exists(lstResults.SelectedItem.ToString()))
{
//Drag and drop!
_canDrag = false;
DataObject dtObj = new DataObject(DataFormats.FileDrop, lstResults.SelectedItem.ToString());
DoDragDrop(dtObj, DragDropEffects.Copy);
}
}
[/XCODE]
With this code, I can drag and drop and the mouse icon looks correct, but when I drop no file is copied. Help!
[XCODE] private void lstResults_MouseMove(object sender, MouseEventArgs e)
{
//If the mouse is in a draggable state and there is a selected item
if (_canDrag && (lstResults.SelectedIndex != -1))
//make sure the string refers to a real, existing file
if (File.Exists(lstResults.SelectedItem.ToString()))
{
//Drag and drop!
_canDrag = false;
DataObject dtObj = new DataObject(DataFormats.FileDrop, lstResults.SelectedItem.ToString());
DoDragDrop(dtObj, DragDropEffects.Copy);
}
}
[/XCODE]
With this code, I can drag and drop and the mouse icon looks correct, but when I drop no file is copied. Help!