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

2 posts, 0 answers
  1. Dexter
    Dexter avatar
    34 posts
    Member since:
    Dec 2012

    Posted 27 Jul 2014 Link to this post

    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;
            }
        }
    }
  2. Kalin
    Admin
    Kalin avatar
    1208 posts

    Posted 29 Jul 2014 Link to this post

    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.
     
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top