Copy drag between listbox and scheduleview

7 posts, 1 answers
  1. Barnes
    Barnes avatar
    17 posts
    Member since:
    May 2012

    Posted 12 Jul 2012 Link to this post

    Hi,

    I have a scenario where I have a listbox containing custom appointments that I want to drag to a radscheduleview. When a user drags from the listbox and drops into the scheduleview the item is removed from the lstbox. When the user drags and drops while pressing the control key the item in the listbox is copied and is not removed when the item is dropped into the schedule.

    What I would like is for the listbox items not to be removed when dragging and dropping to the scheduleview without the need for the user to press the control key. Do you have an example of this?

    Thanks
  2. Answer
    Sandi Markon
    Sandi Markon avatar
    101 posts
    Member since:
    Jul 2012

    Posted 16 Jul 2012 Link to this post

    I believe what you need to do, is to create a custom listbox drag & drop behavior class.

    You inherit from Telerik.Windows.DragDrop.Behaviors.ListBoxDragDropBehavior and override the IsMovingItems method inside that class.                             
    public class ListBoxCustomDragDropBehavior : ListBoxDragDropBehavior
       {
           public ListBoxCustomDragDropBehavior()
           {
                
           }
     
           // this override enables only copies of objects, not their movement
           protected override bool IsMovingItems(DragDropState state)
           {
               return false;
           }

    You then add an instance to this class in XAML:
    <ListBox ItemsSource="{Binding BlaBlaItems}">
                        <drag:ListBoxDragDrop.Behavior>
                            <local:ListBoxCustomDragDropBehavior />
                        </drag:ListBoxDragDrop.Behavior>
    </ListBox>

    The namespace for "<drag:..." is Telerik.Windows.DragDrop.Behaviors.
  3. DevCraft banner
  4. Barnes
    Barnes avatar
    17 posts
    Member since:
    May 2012

    Posted 16 Jul 2012 Link to this post

    Thanks Sandi,

    That worked perfectly, who would have thought it would be so simple? Luckily I already had a custom listbox drag & drop behaviour class. I just couldn't figure out where I was supposed to add the logic to achieve this.

    Much appreciated,

    Barnes
  5. Christopher
    Christopher avatar
    1 posts
    Member since:
    Apr 2015

    Posted 07 Apr 2015 in reply to Sandi Markon Link to this post

    Hi,

    I'm using IsMovingItems and set the ListBoxDragDropBehavior correct in XAML. The dragged element correctly remains in the source listBox, but if I drag the same element multiple times it will not be copied in the destination listBox.

     

    Best

    Christopher

  6. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 08 Apr 2015 Link to this post

    Hi Christopher,

    When the desired behavior of the drag and drop operation between two RadListBox controls or between RadListBox and RadScheduleVuew as discussed in this thread needs to be customized all you need to do is create a custom ListBoxDragDropBehavior. When creating a behavior that will cause the dragged item to not be moved by the operation all that you need to do is override the IsMovingItems() method.

    I tested the desired behavior in the current version of our Telerik UI for WPF and SIlverlight in both ListBox to ListBox and ListBox to ScheduleView scenarios and in all of our tests overriding the IsMovingItems method leads to the expected drag and drop behavior.

    I recorded a short video for you showing the observed behavior on our side. If we have missed something please let us know. You can find the used in the recording sample project here.

    Regards,
    Vladi
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. Jesper
    Jesper avatar
    3 posts
    Member since:
    Mar 2014

    Posted 17 Dec 2015 Link to this post

    I have the same problem on a RadGridView... I'm removing the Appointment from the ScheduleView, but all i want is to drag a copy from the Schedule to the RadGridView.

     The appointment is shown in the RadGridView but it is also removed from the scheduleview which is not supposed...

     Is there a solution for that?

    Thanks

  8. Rosi
    Admin
    Rosi avatar
    2527 posts

    Posted 18 Dec 2015 Link to this post

    Hi,

    To implement the task you can inherit ScheduleViewDragDropBehavior class and override its DragDropCompleted(DragDropState state) method. The state parameter have a  SourceAppointmentsSource property- Holds a reference to the AppointmentsSource collection of the drag source. You can use this to change the behavior.

    For more details please refer to our documentation.

    Regards,
    Rosi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
DevCraft banner