473,395 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 5831
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.SelectedItem.ToString();
}

On receiving side:

private void X_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void X_DragDrop(object sender, DragEventArgs e)
{
string droppedString = (String)e.Data.GetData(DataFormats.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.SelectedItem.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(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void X_DragDrop(object sender, DragEventArgs e)
{
string droppedString = (String)e.Data.GetData(DataFormats.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 StringCollection...no luck)

Simplified example, works only with single strings:

namespace DragTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SourceListBox.Items.Add("Item 1");
SourceListBox.Items.Add("Item 2");
SourceListBox.Items.Add("Item 3");
SourceListBox.Items.Add("Item 4");
SourceListBox.Items.Add("Item 5");
}

private void SourceListBox_MouseDown(object sender,
MouseEventArgs e)
{
//
// Single string
//
string s = SourceListBox.SelectedItem.ToString();
DoDragDrop(s, DragDropEffects.Copy);
}

private void TargetListBox_DragEnter(object sender,
DragEventArgs e)
{
//
// Single string
//
if (e.Data.GetDataPresent(DataFormats.StringFormat))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}

private void TargetListBox_DragDrop(object sender,
DragEventArgs e)
{
//
// Single strings
//
string droppedString =
(String)e.Data.GetData(DataFormats.Text);
TargetListBox.Items.Add(droppedString);
}
}
}

Jun 16 '06 #4

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

Similar topics

0
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
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...
2
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...
3
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== ...
1
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...
2
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...
0
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...
3
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
2
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...
0
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...

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.