472,959 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,959 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 2237
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, Im back here to show the new version of the drag & drop table columns (original script ). Ive found some issues with the old script, specially when trying to use 2 tables with...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.