How to find the DragDrop source ?

  • Thread starter Thread starter Nick Carter
  • Start date Start date
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
 
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')
 
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
 
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.
 
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
 
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
 
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.
 
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')
 
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
 
Back
Top