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

DragAndDrop - A little unclear about e.Handled, cancelling a drag, and e.AllowedEffects?

1 Answer 68 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 20 Dec 2013, 08:35 PM
I have three listboxes where I can drag and drop items back and forth.

Depending on some arbitrary logic, I want to disallow some drops.  For example, let's say the lists contain integers and I want to disallow dropping "even" integers onto one of the lists.

I have attached the following events to the listboxes: OnDragInitialize, OnDragOver, OnDrop, and OnDragDropCompleted with handledEventsToo set to True.

-Inside OnDragInitialize I fill my payload object, create a dragvisual, and set e.AllowedEffects = "All".  Do I need to set e.Handled here for anything?

-Inside OnDragOver, I query the payload object for "even" integers and update the dragvisual based on the result.  For disallowed drops, I set e.AllowedEffects = "None".  Is that what I'm supposed to be doing to indicate the drop is not currently allowed?  Does doing that stop the "OnDrop" and "OnDragDropCompleted" events from firing if the user drops the object?  Am I supposed to do anythign with e.Handled here?

-Inside OnDrop, I query the dragvisual to see if the object can be dropped (should I be querying e.AllowedEffects instead or will it only fire when allowed?) and then perform the appropriate actions to manage the lists if allowed.  Should I do something with e.Handled here?

Basically, I'm a little cloudy on when/where to set e.AllowedEffects, and what I use e.Handled for and how those things affects downstream events.  I've read the documents about the events but they don't have very much detail about the flow between them.


1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 25 Dec 2013, 02:30 PM
Hi Rob,

Let me get to your questions one by one:

-Inside OnDragInitialize I fill my payload object, create a dragvisual, and set e.AllowedEffects = "All".  Do I need to set e.Handled here for anything?
The e.Handled is used to distribute the events the same as any other routed event, so you have to set it if you have a multi level structure that supports drag and drop on multiple visual levels.

-Inside OnDragOver, I query the payload object for "even" integers and update the dragvisual based on the result.  For disallowed drops, I set e.AllowedEffects = "None".  Is that what I'm supposed to be doing to indicate the drop is not currently allowed?  Does doing that stop the "OnDrop" and "OnDragDropCompleted" events from firing if the user drops the object?  Am I supposed to do anythign with e.Handled here?
The statement for e.Handled here is the same. As to the Effects, you can use them to check in the Drop and DragDropCompleted event to check whether to execute the dedicated logic.

-Inside OnDrop, I query the dragvisual to see if the object can be dropped (should I be querying e.AllowedEffects instead or will it only fire when allowed?) and then perform the appropriate actions to manage the lists if allowed.  Should I do something with e.Handled here?
Basically the previous answer contains the information you are looking for. As for the Handled, it's the same notation. 

Hope this makes sense! 

Regards,
Nik
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
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 >>
Tags
DragAndDrop
Asked by
Rob
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or