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

Keep Item In List after drag/drop

1 Answer 159 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
heavywoody
Top achievements
Rank 1
heavywoody asked on 02 Jul 2013, 07:23 PM
I am using two RadListBoxes as well as a ItemCollection.  The are bound to observable collections of business objects.    When I drag items between them, I don't want the item to be removed from the collection, but rather just a copy placed where it was dragged to.  How would I keep the items in the list?   It seems no matter what I do, the item is removed from the list that it was drug from.

1 Answer, 1 is accepted

Sort by
0
heavywoody
Top achievements
Rank 1
answered on 03 Jul 2013, 12:39 AM
I think I figured it out by looking at different examples.  Inheriting the ListBoxDragDropBehavior is the key.   Maybe I am missing the source, but I couldn't find much documentation on it, which would be very helpful.  But based on a same you had, I played around until I got it to do what I wanted.  SO this does three things:

1) Won't remove an item from a source listbox
2) Won't allow use to drag/drop into the same listbox
3) Won't allow a duplicate to be dropped into a listbox

public class CustomDragDropBehavior : ListBoxDragDropBehavior
{
public override void Drop(DragDropState state)
{
            if(!state.IsSameControl)
            {
   foreach (object o in state.DraggedItems)
   {
                    if(!state.DestinationItemsSource.Contains(o))
                    state.DestinationItemsSource.Add(o);
                }
            }
//base.Drop(state);
}

public override void DragDropCompleted(DragDropState state)
{
            foreach (var item in state.DraggedItems)
            {
               // state.SourceItemsSource.Remove(item);
            }
           // base.DragDropCompleted(state);
}

        public override bool CanDrop(Telerik.Windows.DragDrop.Behaviors.DragDropState state)
        {
            return !state.IsSameControl;
        }

protected override bool IsMovingItems(DragDropState state)
{
return !state.IsSameControl;
}
Tags
DragAndDrop
Asked by
heavywoody
Top achievements
Rank 1
Answers by
heavywoody
Top achievements
Rank 1
Share this question
or