2

I have a ListBox control, that contains a few items that display attachments (files or directories).

I have successfully allowed users to drag and drop items from their desktop to the ListBox , but I have not been able to allow the user to drag and drop items from the ListBox to their desktop.

Is this possible?

user842818
  • 305
  • 1
  • 5
  • 14

1 Answers1

4

Hope this helps you get started (assuming list box is just a list of files with their full paths):

Private Sub ListBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles ListBox1.MouseDown
  Dim fileList As New Collections.Specialized.StringCollection
  fileList.Add(ListBox1.SelectedItem.ToString)

  Dim dataObj As New DataObject
  dataObj.SetFileDropList(fileList)

  ListBox1.DoDragDrop(dataObj, DragDropEffects.Copy)
End Sub
LarsTech
  • 80,625
  • 14
  • 153
  • 225
  • Don't forget to prevent dragging back onto self - [refer here](http://stackoverflow.com/a/11754362/737393) – CrazyTim Aug 01 '12 at 07:24