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

Copy drag between listbox and scheduleview

6 Answers 141 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Barnes
Top achievements
Rank 1
Barnes asked on 12 Jul 2012, 09:40 AM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Sandi Markon
Top achievements
Rank 1
answered on 16 Jul 2012, 11:07 AM
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.
0
Barnes
Top achievements
Rank 1
answered on 16 Jul 2012, 11:14 AM
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
0
Christopher
Top achievements
Rank 1
answered on 07 Apr 2015, 06:43 AM

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

0
Vladi
Telerik team
answered on 08 Apr 2015, 07:26 AM
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.

 
0
Gabriell
Top achievements
Rank 1
answered on 17 Dec 2015, 11:00 AM

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

0
Rosi
Telerik team
answered on 18 Dec 2015, 06:30 AM
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
Tags
ScheduleView
Asked by
Barnes
Top achievements
Rank 1
Answers by
Sandi Markon
Top achievements
Rank 1
Barnes
Top achievements
Rank 1
Christopher
Top achievements
Rank 1
Vladi
Telerik team
Gabriell
Top achievements
Rank 1
Rosi
Telerik team
Share this question
or