This is a migrated thread and some comments may be shown as answers.

Determining source on a DropInfoEvent

7 Answers 100 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
GEB
Top achievements
Rank 1
GEB asked on 26 Dec 2008, 07:50 PM
When I receive a DropInfoEvent for an element (in this case an Image), how do I determine the source of the Drag?  For example, I have 2 ListBoxes and 1 Image.  I can drag from either ListBox to the Image.  When I get a DropInfoEvent for the Image, how can I tell which ListBox it is from?

7 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 29 Dec 2008, 01:39 PM
Hi Gary,

There are several approaches:

The source of the DragDrop most probably will be a ListBoxItem, so you can get its Parent parent property which will be the respective ListBox.

To get the source, use (in the handler)

e.Options.Source

You can also put as a Payload of the DragDrop a custom object that will hold additional information for the drag drop which will be recognized and used by the destination.

Hopefully this will help you,

Kind regards,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
GEB
Top achievements
Rank 1
answered on 02 Jan 2009, 07:21 AM
It appears as though e.Options.Source is not being set.  When the event is received, e.Options.Destination has been set correctly, so I can determine the destination, but when I look at e.Options.Source.Name it is blank.  Is this perhaps a bug?
0
Miroslav
Telerik team
answered on 06 Jan 2009, 11:03 AM
Hi Gary,

I had a look at some samples of DragDrop where the source property is correctly set, not a null value.

Could you confirm that the e.Options.Source value is null?

If it is, then this indeed is a bug and I may need more details on how to reproduce it or, best, a sample project where this happens.

Please note that the Source should be set to the item that started the DragDrop (and has its AllowDrag property set to true. In your case this may be a ListBoxItem and not a ListBox (which typically will have a name).

Kind regards,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
GEB
Top achievements
Rank 1
answered on 06 Jan 2009, 04:42 PM
Let me explain a bit more about what I'm trying to do, then see if you have any recommendations.

I am using your drag-and-drop example, except I'm dragging from a ListBox (#1) into another ListBox (#2).  When the object is dragged into the destination ListBox (#2), I doNOT delete it from the source ListBox (#1)  (unlike your example).  There is a 3rd object, which is a trash can image.  When an object is placed in the second ListBox (#2) (which means that it is also in the first ListBox), I only want the user to be able to drag it to the trash can.  They cannot drag it back into the first ListBox (because it is already there).  And, the user is not allowed to drag from the first ListBox (#1) to the trash can. 

When I get an event, I want my code-behind to know if the user is trying to drop the element back into the first ListBox.  Or, is trying to drag from the first ListBox to the trash can. When I check the name of the destination (or target) as you recommended, it is always blank when I do a ToString().

What I'm looking for is a mechnaism where I do not have to change my payload, but to be able to get the information I need directly from the event, if possible.  That would include both Source and Destination of either ListBox #1, ListBox #2 or trash can.
0
GEB
Top achievements
Rank 1
answered on 06 Jan 2009, 05:12 PM
Also, I have not tried getting the parent, in case the source is indeed a ListBoxItem.  I'll give this a try later today.
0
GEB
Top achievements
Rank 1
answered on 07 Jan 2009, 08:45 PM
In running this thriugh the debugger, I observed that e.Options.Source was indeed a ListBoxItem, the name was "", and the parent was NULL.  Therefore, I'm not able to get the name of the source ListBox.  This sounds like a bug to me in that the ListBoxItem parent should be set to the ListBox.  This should be easy to reproduce.  In my case, the destination was an image, and the source is a ListBox.
0
Miroslav
Telerik team
answered on 08 Jan 2009, 08:44 AM
Hello Gary,

Yes, I managed to reproduce this and indeed the parent of the ListBoxItem is null. Surely, I did not expect that!

I can offer several workarounds:

1. Use a more verbose payload: The payload will be a class that will hold both the item and its parent. On DragQuery the item will create the Payload and add itself. Then its parent (the ListBox) will also handle the event and will add itself too.

2. Handle the DragInfo event on the ListBox in its DragStatus.DragComplete phase, then the ListBox can check if the Destination of the drop is the recycle bin and then remove the item accordingly.

Hopefully this will work in your case,

Regards,
Miroslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
DragAndDrop
Asked by
GEB
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
GEB
Top achievements
Rank 1
Share this question
or