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(lbF iles.SelectedIn dices.Count - 1) As String
Dim i As Integer = 0
Dim J As Integer
For J = 0 To dvFiles.Count - 1
If lbFiles.GetSele cted(J) = True Then
targettFiles(i) = dvFiles.Item(J) .Row.Item("File Name")
i += 1
End If
Next
Dim data As New DataObject(Data Formats.FileDro p, 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(dvF iles.Count - 1) As String
Dim J As Integer
For J = 0 To dvFiles.Count - 1
targetFiles(J) = dvFiles.Item(J) .Row.Item("File Name")
Next
Dim data As New DataObject(Data Formats.FileDro p, 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 2 3122
This is code (5 mins old and working). It takes from a listview but should
work same for listbox.
Private Sub lvwSongs_MouseD own(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles lvwSongs.MouseD own
Dim lvw As ListView
lvw = sender
Dim dataObj As DataObject
dataObj = New DataObject
Dim arr() As String
ReDim arr(lvw.Selecte dItems.Count - 1)
Dim li As ListViewItem
Dim i As Int16
For Each li In lvw.SelectedIte ms
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.c om... 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(lbF iles.SelectedIn dices.Count - 1) As String Dim i As Integer = 0 Dim J As Integer For J = 0 To dvFiles.Count - 1 If lbFiles.GetSele cted(J) = True Then targettFiles(i) = dvFiles.Item(J) .Row.Item("File Name") i += 1 End If Next Dim data As New DataObject(Data Formats.FileDro p, 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(dvF iles.Count - 1) As String Dim J As Integer For J = 0 To dvFiles.Count - 1 targetFiles(J) = dvFiles.Item(J) .Row.Item("File Name") Next Dim data As New DataObject(Data Formats.FileDro p, 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
On Mon, 15 Dec 2003 01:19:57 GMT, "Lloyd Sheen"
<sq************ *******@tostops pamhotmail.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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 document, I would like the image of
the user document to be displayed.
The behavior of the dragged item needs to be not unlike that of the cards in
solitare. I can do the standard drag & drop stuff but don't know how to
change the dragged items shape...
|
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 solution on the internet, with limited success.
I do have code to drag an attachment directly from Outlook to a form, but
not a whole message.
I want to have access to an object reprensenting the message so I can bust
out the message and...
|
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 structure in TreeView2
(putting files in different folders and such...like you do when you create a
structure for burning a CD).
I have two questions.
1. How can I remember the full path from TreeView1 (when it comes time to
actually do...
|
by: VB Programmer |
last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!
|
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:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchimpdragdrop.asp
It works fine, but I have another problem. I want to create functionality
like a Windows Explorer. This means, if I select some items from list view No
1 and drag&drop this to the list view No 2, then I want to mark automatically
| |
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, including between controls and windows.
In the past when I've implemented Drag and Drop in other projects, I've always passed the item being dragged (for example the listviewitem or the treenode) to the DoDragDrop and then retrieved it in the...
|
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 can see that the order I get in my
drop event is not always the same as displayed in the explorer window.
Further more the order changes depending on how many files/dirs are
|
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 drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented.
I´ve also commented the whole code so you guys can easier understand it engine.
What exactly we need when trying to make a column drag &...
|
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 select 3
files from a windows explorer and I move it in a listbox in my
activeX, I find my 3 files added in the listbox but if I use my
activeX in a web form and I select 3 file from a windows explorer in
the listBox find only 1 file the file on...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
| |