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

How to reject a particular object when multiple objects are dropped at the same time?

1 Answer 37 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Dexter
Top achievements
Rank 1
Dexter asked on 27 Jul 2014, 06:14 PM
Hello, I would like to enquire on a solution to the scenario as per title. Below is what I have currently, which obviously doesn't work as the Drop is just 1 event itself. If I accept, everything will be accepted, and if I reject, everything will be rejected at once.

private void ListBoxIssue_OnPreviewDrop(object sender, DragEventArgs e)
{
    var droppedObject = DragDropPayloadManager.GetDataFromObject(e.Data, typeof(CommsItem));
    List<CommsItem> listCommsItem = ((List<object>) droppedObject).Cast<CommsItem>().ToList();
    //droppedObject is an object, which is of List<Object>, which the objects in the list are CommsItem
    foreach (CommsItem commsItem in listCommsItem)
    {
        if (commsItem.Serial == "2008")
        {
            e.Handled = true;
            e.Effects = DragDropEffects.None;
        }
        else
        {
            e.Handled = false;
            e.Effects = DragDropEffects.All;
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 29 Jul 2014, 11:06 AM
Hi Dexter,

Could you please share some more details about the exact scenario, are you using a ListBoxDragDropBehavior and are you dragging between two ListBoxes? If so what I can suggest you would be implement a custom ListBoxDragDropBehavior and to manually add the desired items in the destination ItemsSource in the Drop method and manually remove the same ones from the SourceItemsSource in the DragDropCompleted method. For your convenience I have prepared a sample project which demonstrates the exact approach - drag multiple items from the first ListBox to the one below, only one of the items will be moved.

Hope this helps.

Regards,
Kalin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
DragAndDrop
Asked by
Dexter
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or