473,473 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Drag&Drop for multiple items

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

Nov 20 '05 #1
2 3100
This is code (5 mins old and working). It takes from a listview but should
work same for listbox.

Private Sub lvwSongs_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles lvwSongs.MouseDown
Dim lvw As ListView
lvw = sender
Dim dataObj As DataObject
dataObj = New DataObject
Dim arr() As String
ReDim arr(lvw.SelectedItems.Count - 1)

Dim li As ListViewItem
Dim i As Int16
For Each li In lvw.SelectedItems
arr(i) = li.Text
i += 1
Next
dataObj.SetData("FileDrop", arr)
lvw.DoDragDrop(dataObj, DragDropEffects.All)
End Sub

Ensure that listbox is set to handle multiple selection and that code is in
the mousedown event.

"Dolorous Edd" <ed******************@tin.it> wrote in message
news:dp********************************@4ax.com...
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

Nov 20 '05 #2
On Mon, 15 Dec 2003 01:19:57 GMT, "Lloyd Sheen"
<sq*******************@tostopspamhotmail.com> wrote:
This is code (5 mins old and working). It takes from a listview but should
work same for listbox.

Thank you very much. I still don't understand what was wrong with the
previous one, since the two look pretty much the same to me, but it
works now!
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: memHog | last post by:
I am trying to create a windows application that will perform drag and drop between a usercontrol on a toolbar and a "user document". As the user control is being dragged accross the user...
6
by: David Anderson | last post by:
Does anyone know how to drag&drop a message with attachments from Outlook (2002 or 2003) in to a VB.Net windows form. This is really stumping me. I've spent a fair amount of time trying to find a...
1
by: Terry Olsen | last post by:
My first time using TreeViews. I have TreeView1 set up to display my directory structure just like Windows Explorer. I can drag & drop files and folders over to TreeView2. I can re-arrange the...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
1
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: ...
1
by: SteveDouglas | last post by:
Hi all, I am currently writing an application in VB.NET that has a lot of controls (treeviews/listviews/labels and so forth) that represent "things" that need to be draggable from place to place,...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
5
by: Romulo NF | last post by:
Greetings, I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with...
2
by: deccio | last post by:
I have create an activex Control with Visual studio 2005 and framework 2.0 in c# to add drag & drop functionality to upload multi file. When I use it in a windows form it work fine. Infact if I...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.