D
Dolorous Edd
Hi,
for a program I'm working on I need to be able to drag multiple files
between Windows Explorer and a ListBox, in both directions.
Implementing the "drag in" was pretty easy, but I can't find a way to
export more than on item at time.
The ideal result would be to be able to drag the selected files, but
as soon as I click on the LB to do the drag a new selection is made
that cancels the current one and by searching with google it seems
that the problem has no simple solution (btw, I'd be glad to be proven
wrong on this)
Anyway, since I normally need to drag every element, i decided to make
the drags automatically select every element, but it seems to work
only with a single file, and I can't understand why.
The code that works is the following:
Dim targetFiles(lbFiles.SelectedIndices.Count - 1) As String
Dim i As Integer = 0
Dim J As Integer
For J = 0 To dvFiles.Count - 1
If lbFiles.GetSelected(J) = True Then
targettFiles(i) = dvFiles.Item(J).Row.Item("FileName")
i += 1
End If
Next
Dim data As New DataObject(DataFormats.FileDrop, targetFiles)
DoDragDrop(data, DragDropEffects.Copy)
lbFiles is my ListBox and dvFiles is the DataView associated with it.
This was made for the multiple selectione, hence the "for" part, and
since the selection is always single it works.
To make it drag every file, I simply changed the way targetFiles is
created, by filling it with all the elements, and the result is the
following:
Dim targetFiles(dvFiles.Count - 1) As String
Dim J As Integer
For J = 0 To dvFiles.Count - 1
targetFiles(J) = dvFiles.Item(J).Row.Item("FileName")
Next
Dim data As New DataObject(DataFormats.FileDrop, targetFiles)
DoDragDrop(data, DragDropEffects.Copy)
If I drag on Windows Explorer with this version doesn't happen
anything, and if I drag on Nero Burning Rome (the real purpose of the
project) it crashes.
I also tried to define data as an array, and add a file per element,
or to make a DoDragDrop for every file, but it didn't work either.
Does anybody has an idea of how to make it work?
Thak yon in advance
for a program I'm working on I need to be able to drag multiple files
between Windows Explorer and a ListBox, in both directions.
Implementing the "drag in" was pretty easy, but I can't find a way to
export more than on item at time.
The ideal result would be to be able to drag the selected files, but
as soon as I click on the LB to do the drag a new selection is made
that cancels the current one and by searching with google it seems
that the problem has no simple solution (btw, I'd be glad to be proven
wrong on this)
Anyway, since I normally need to drag every element, i decided to make
the drags automatically select every element, but it seems to work
only with a single file, and I can't understand why.
The code that works is the following:
Dim targetFiles(lbFiles.SelectedIndices.Count - 1) As String
Dim i As Integer = 0
Dim J As Integer
For J = 0 To dvFiles.Count - 1
If lbFiles.GetSelected(J) = True Then
targettFiles(i) = dvFiles.Item(J).Row.Item("FileName")
i += 1
End If
Next
Dim data As New DataObject(DataFormats.FileDrop, targetFiles)
DoDragDrop(data, DragDropEffects.Copy)
lbFiles is my ListBox and dvFiles is the DataView associated with it.
This was made for the multiple selectione, hence the "for" part, and
since the selection is always single it works.
To make it drag every file, I simply changed the way targetFiles is
created, by filling it with all the elements, and the result is the
following:
Dim targetFiles(dvFiles.Count - 1) As String
Dim J As Integer
For J = 0 To dvFiles.Count - 1
targetFiles(J) = dvFiles.Item(J).Row.Item("FileName")
Next
Dim data As New DataObject(DataFormats.FileDrop, targetFiles)
DoDragDrop(data, DragDropEffects.Copy)
If I drag on Windows Explorer with this version doesn't happen
anything, and if I drag on Nero Burning Rome (the real purpose of the
project) it crashes.
I also tried to define data as an array, and add a file per element,
or to make a DoDragDrop for every file, but it didn't work either.
Does anybody has an idea of how to make it work?
Thak yon in advance