473,407 Members | 2,546 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,407 software developers and data experts.

Passing data for Drag & Drop

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 DragDrop event handler to find out what's been dropped.

This of course means making a special case for each type of droppable object (the listviewitem, tree node or whatever) and then working out from stuff I've put in it's .tag what the "thing" is that the dropped item refers to.

In this project I could be dropping all sorts of controls, labels, textboxes, pictureboxes, treenodes, listviewitems and so on, and I don't really care what the forms object being dropped is, all I care about is what data that object represents in my application model.

The easy way seems to be not to pass the forms object being dragged to the DoDragDrop function, but to pass some user-data instead. That way the receipient of the drop can tell what the data being dragged is, and doesn't really care what the physical forms object is. I'm never going to 'move' the forms object being dragged, I'm going to change the data model, and then redraw things.

It seems to work ok if I pass a System datatype like a string or a long, I can retrieve the data in the DragDrop event of the target control using GetData, however I could really do with passing a user-defined structure rather than an intrinsic data-type.

I can't get that to work. I can pass the structure to DoDragDrop ok - that works, but I can't find a way to get it back at the other end, from the e.data returned in the DragDrop event.

I can't seem to find a conversion that will work on e.data that will convert the data to something of type "myproject.mystructure". Fine if I pass a system data type, conversions to "System.String" work for example, so I've resorted to converting my structure to a string, passing that to DoDragDrop, and turning it back again in the events. It's not very efficient, especially as I want to know what is being passed in other events like DragEnter as well, so I'm doing a lot of converting, and if what I'm dragging is a multiple-selection then the conversion to a string is a real pain.

Is there a way to pass a user-defined structure to DoDragDrop and get it back again in DragDrop at the target end? Then I could always pass an array of mystructure (which might only contain one element) by reference to every Drag & Drop operation in the whole application, and it would be much neater.

Regards,
Steve
Feb 10 '07 #1
1 2276
In reply to my own thread, I suddenly realised that all this passing of data in order to know what object(s) are being dragged is really unnecessary.

There can only ever be one Drag and Drop operation in progress at any given time, so I might as well build my list of objects in global scope before I call DoDragDrop, and then I can access them from anywhere I like.

This makes the whole thing a lot simpler and faster than trying to pass data all over the place.

It's maybe not as neat as 'sending' the data along with DoDragDrop, but it's a lot faster and a lot less messy, and the structure I build to represent the dragged data can be anything I like.
Feb 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Plumer | last post by:
Hello everyone, Yesterday I posted a message about implementing drag & drop in a TreeView control. I'm having real difficulty getting this to work -- the process seems to be incredibly...
2
by: Grey | last post by:
I need to design a workflow application with C#. I want to design an UI with some workflow components which they can be drag & drop anywhere in order to design the workflow for the application...
2
by: Dave Veeneman | last post by:
Is there a simple way to pass drag-and-drop events to a child control in a UserControl? Here's an example: I have created a UserControl which contains a treeview and some text boxes. I want to...
2
by: Barry Moon | last post by:
Hi Can anyone give me any help with passing an object across processes, via drag and drop? I've written a custom ListView control, which supports dragging and dropping of its items. The...
2
by: Ivo Tcholakov | last post by:
Is it possible to drag and drop controls in an aspx page at runtime ? Meaning i have developed a ASP.NET web form, the web form is now downloaded in IE - now can i have this form to detect mouse...
6
by: jojobar | last post by:
Hello, I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I tried to run it under firefox browser but it did not run. If I want to use this feature in a commercial product...
3
by: Goldwind | last post by:
Hi, I"m trying to use drag & drop of text from one text box to another but without suceess. Microsoft presented an example in "101 code samples" BUT in this example the code select and drag all...
1
by: Neil West | last post by:
I’m trying to drag & drop listview items between two instances of my app. The actual data that’s passed in DoDragDrop is an arraylist that’s been serialized to a memorystream. The contents...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...
0
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...

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.