Determining source on a DropInfoEvent

8 posts, 0 answers
  1. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 26 Dec 2008 Link to this post

    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?
  2. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 29 Dec 2008 Link to this post

    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.
  3. DevCraft banner
  4. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 02 Jan 2009 Link to this post

    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?
  5. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 06 Jan 2009 Link to this post

    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.
  6. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 06 Jan 2009 Link to this post

    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.
  7. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 06 Jan 2009 Link to this post

    Also, I have not tried getting the parent, in case the source is indeed a ListBoxItem.  I'll give this a try later today.
  8. GEB
    GEB avatar
    228 posts
    Member since:
    Dec 2008

    Posted 07 Jan 2009 Link to this post

    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.
  9. Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 08 Jan 2009 Link to this post

    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.
Back to Top
DevCraft banner