Disable Drop Depending on Data Properties

5 posts, 0 answers
  1. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 12 Jul 2013 Link to this post

    I have a databound listbox that is bound to a class call Animal.   On another form is several databound listboxes that are different types of animals.  All listboxes use the Animal class.   So what I want to do is when a user grabs an Animal class from the source listbox and drags it over to the form, depending on Animal.Type, only the listbox named the Animal.Type can accept the drop.

    I thought maybe I could do this by using DragEnter.  But I can't seem to get the business object out of the data object.  I thought if I could, I could check it, and if it matched the Listbox name, I would enable drop.  If not, I would disable drop on that listbox.  I would do that to all of them.

    Is this possible? I have been wrecking my brains and cannot figure out how to get the data out and what property to put it in.  All the examples seem to talk about drag/drop strings.  I have full blown bound objects.

    So it is conditionally dropping depending on a property of the object being dragged.
  2. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 05 Sep 2013 Link to this post

    Anyone?  How do I get the object(s) that are being dragged?  Because I have to know a property of the object being dragged to set the drop behavior.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Nick
    Admin
    Nick avatar
    593 posts

    Posted 06 Sep 2013 Link to this post

    Hi ,

    You can do that by using the DragDropPayloadManager(Both to set the data and extract it). You can then use the DragEffects to make the Drop impossible (Efects = None).

    Hope this helps!  

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. heavywoody
    heavywoody avatar
    79 posts
    Member since:
    Oct 2009

    Posted 07 Sep 2013 Link to this post

    Ok, one other question.  This works fine.  But I have the condition that if the user holds down the CTRL key while they drag/drop, the logic I talked about overruled and they can drop it on anything.  But I can't seem to capture the CTRL with drag/drop at the same time.  How would you suggest I do that do the drag/drop events know the the CTRL key is held down?
  6. Nick
    Admin
    Nick avatar
    593 posts

    Posted 11 Sep 2013 Link to this post

    Hi ,

    You can handle the Keyboard key down events, and check if the key is Ctrl, to raise a boolean flag indicating the state of the button. You should subscribe tot he event with HandledEventsToo set to true, since something may be handling them in the process. 

    Hope this helps! 

    Regards,
    Nik
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top
UI for WPF is Visual Studio 2017 Ready