How to find the DragDrop source ?

N

Nick Carter

I have a 4 listboxes. I want to drag items from listbox1 onto listbox2 and
from listbox3 onto listbox4. I don't want listbox2 to accept items from
listbox3. How can I determine which listbox is the source of the drag
operation ?

Nick Carter
 
J

jwallison

The OLH has an example of this listed in the Control.DoDragDrop topic.

--
Regards,

Jim Allison
(e-mail address removed)
(de-mung by removing '.1')
 
N

Nick Carter

Jim,

This example doesn't do what I want. It does show how to implement drag and
drop but it isn't checking the source. If you add another listbox to the
form then it can't tell which listbox is the source.

Nick
 
?

=?ISO-8859-1?Q?Christian_Fr=F6schlin?=

Nick said:
Jim,

This example doesn't do what I want. It does show how to implement drag and
drop but it isn't checking the source. If you add another listbox to the
form then it can't tell which listbox is the source.

You could handle the ItemDrag event of the source listviews
and store the information at the time when the drag starts.
 
1

100

Hi Nick,
You cannot find the source of the drag & drop operation. This is the idea
behind the UDT I believe.
If the drag and drop occurs between components in the same application you
can have a designated *global* variable which can hold the source of the
drag operation. If the data can be dragged across the application
boundraries, though, what you might wanna do is to put a new piece of
information in the DataObject that will provide the target with some info
about the source. Then targets can reject or accept dragged object via
checking out that info.

HTH
B\rgds
100
 
N

Nick Carter

100,

Ok, I think the DataObject solution is the one that I will go with. It seems
odd that the source information has to be bolted on instead of built in but
now that I know I can at least move forwards.

Thanks.

Nick
 
?

=?ISO-8859-1?Q?Christian_Fr=F6schlin?=

Nick said:
Christian,

But that will only work with listviews - I am using listboxes.

You can use the MouseDown event instead. Of course, that will
also fire when not dragging, but the only important bit is
that it should not fire between drag start and drag drop.
 
J

jwallison

The sample source that I referred to uses listboxes, and the technique of
flagging the source listbox when the drag is initiated (see
ListDragSource_MouseDown) is also well-documented in the sample.

--
Regards,

Jim Allison
(e-mail address removed)
(de-mung by removing '.1')
 
N

Nick Carter

Jim,

The following line in the MouseDown event names the listbox explicitly:-

indexOfItemUnderMouseToDrag = ListDragSource.IndexFromPoint(e.X, e.Y);

so it doesn't know what the source is because it is hard wired.
save the "sender" as a private member var of type ListBox or Control

Yes, obviously that would work. I expected there to be a built in solution
but I guess you are saying that there isn't.

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top