473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drag and Drop multiple items

Rob
I've searched for info on how to drag and drop a group of strings (or
any other object) from one control to another. Looked through
articles by Dino Esposito, checked the Forms books by Sells and
MacDonald. You'd think it would be there.

Anyone know?
Jun 15 '06 #1
3 5869
rob
On Thu, 15 Jun 2006 17:23:47 -0400, Rob <Ro*@nospam.com > wrote:
I've searched for info on how to drag and drop a group of strings (or
any other object) from one control to another. Looked through
articles by Dino Esposito, checked the Forms books by Sells and
MacDonald. You'd think it would be there.

Anyone know?


No takers? To qualify this, I *can* retrieve an array of files that
are selected and dropped from explorer. No problem, MSDN has an
example.

But what I need to do is to drag and drop strings or structs, and I
need to handle capturing them myself, in a ListBox or ListView. I can
handle a single string easy enough:

On sending side:

private void OnMouseDown()
{
string s = AListBox.Select edItem.ToString ();
}

On receiving side:

private void X_DragEnter(obj ect sender, DragEventArgs e)
{
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void X_DragDrop(obje ct sender, DragEventArgs e)
{
string droppedString = (String)e.Data. GetData(DataFor mats.Text);
}

So... How would one convert this to use string arrays rather than just
single strings?

Jun 16 '06 #2
rob
On Fri, 16 Jun 2006 03:05:06 -0400, rob <ro*@nospam.com > wrote:
On Thu, 15 Jun 2006 17:23:47 -0400, Rob <Ro*@nospam.com > wrote:
I've searched for info on how to drag and drop a group of strings (or
any other object) from one control to another. Looked through
articles by Dino Esposito, checked the Forms books by Sells and
MacDonald. You'd think it would be there.

Anyone know?
No takers? To qualify this, I *can* retrieve an array of files that
are selected and dropped from explorer. No problem, MSDN has an
example.

But what I need to do is to drag and drop strings or structs, and I
need to handle capturing them myself, in a ListBox or ListView. I can
handle a single string easy enough:

On sending side:

private void OnMouseDown()
{
string s = AListBox.Select edItem.ToString ();
}


Oops...yes, I do have this line in the function above:
DoDragDrop(s, DragDropEffects .Copy);

As mentioned, this does work for single strings. I've tried
building arrays from selected objects, and tried casting the return
type to string[], etc. Something goes wrong each time. The problem
may be with the lack of data type for string[] on the receiving side.
On receiving side:

private void X_DragEnter(obj ect sender, DragEventArgs e)
{
if (e.Data.GetData Present(DataFor mats.Text))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void X_DragDrop(obje ct sender, DragEventArgs e)
{
string droppedString = (String)e.Data. GetData(DataFor mats.Text);
}


So... How would one convert this to use string arrays rather than just
single strings?

Jun 16 '06 #3
Rob
No replies to my previous query for some reason. I'll try to simplify
this. If a form is created with two ListBoxes called 'SourceListBox'
and 'DestListBox', and the code below is hooked into drag-drop events,
this will copy single strings from one box to the other.

If the flag on the source box is set for multi-select, how would the
code need to be adapted for dragging multiple strings? (I have tried
various approaches with string[] and StringCollectio n...no luck)

Simplified example, works only with single strings:

namespace DragTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeCompo nent();
SourceListBox.I tems.Add("Item 1");
SourceListBox.I tems.Add("Item 2");
SourceListBox.I tems.Add("Item 3");
SourceListBox.I tems.Add("Item 4");
SourceListBox.I tems.Add("Item 5");
}

private void SourceListBox_M ouseDown(object sender,
MouseEventArgs e)
{
//
// Single string
//
string s = SourceListBox.S electedItem.ToS tring();
DoDragDrop(s, DragDropEffects .Copy);
}

private void TargetListBox_D ragEnter(object sender,
DragEventArgs e)
{
//
// Single string
//
if (e.Data.GetData Present(DataFor mats.StringForm at))
e.Effect = DragDropEffects .Copy;
else
e.Effect = DragDropEffects .None;
}

private void TargetListBox_D ragDrop(object sender,
DragEventArgs e)
{
//
// Single strings
//
string droppedString =
(String)e.Data. GetData(DataFor mats.Text);
TargetListBox.I tems.Add(droppe dString);
}
}
}

Jun 16 '06 #4

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

Similar topics

0
1287
by: Karuppasamy | last post by:
Hi In a Windows Applications, i want to drag and drag multiple items between two Listboxes. Is it possible to drag and drop multiple items? If yes, how to do that? Waiting for your reply.
0
2605
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot simutate it. Can anyone help? Thanks ************************** previous post: Message 1 in thread
2
4337
by: SamSpade | last post by:
There seems to be two ways to put things on the clipboard ( I don't mean different formats): SetClipboardData and OleSetClipboard If I want to get data off the clipboard do I care how it was put there? What about Drag/Drop; is there more than one way for the source to make data available Is it always OLE?
3
10420
by: Ajay Krishnan Thampi | last post by:
I have a slight problem implementing 'drag and drop' from a datagrid to a tree-view. I have pasted my code below. Someone please advice me on what to do...pretty blur right now. ==code== using System; using System.Drawing; using System.Collections; using System.ComponentModel;
1
3506
by: emferrari | last post by:
Hi everybody I have two treeviews, one of them is only to receive items dragged from the treeview1. I want to know how to drag a full node information to the treeview2. I know how to do that only in a single node operation. Here is my current code: private void trv_Directories_ItemDrag(object sender, ItemDragEventArgs e)
2
3128
by: Dolorous Edd | last post by:
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...
0
1775
by: Robin Tucker | last post by:
Hi there, I have a list box (just happens to be owner draw). When I select multiple items using the CTRL key, the items I have selected become highlighted (obviously). Now, when I click on one of the selected items in order to initiate a Drag operation, the other items are deselected and the item I have just clicked becomes the only one selected! I tested this with a normal list box (not owner draw) on a simple form. I can select...
3
10600
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
2
8156
by: anchi.chen | last post by:
Hi People, Just wondering if any of you have ever come across any javascript examples that will allow one to drag and drop multiple items between lists? That is, users would be able to use the "Shift" or "Ctrl" buttons to select multiple items from LIST 1 and drag them to LIST 2 in one go. I've already have the code to drag and drop between lists but for 1 item at a time. The only method to move multiple items between lists
0
1861
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vS2005 and .net 2.0. for a Windows application. I'm implementing a Drag and Drop between 2 DataGridView controls. It's working fine with just one item being drag and drop. I want to do multiple items drag and drop. Does any one know of any example of such? I only found example for one item and for 2 list controls. The problem that I'm having is when I press the shift key or control key and use the mouse to click the...
0
9531
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,...
0
10459
Oralloy
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...
0
10237
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 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...
1
10187
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,...
0
9055
agi2029
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...
1
7553
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
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();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.