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

Prevent removal from source collection on Drag/Drop

10 Answers 283 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Nick Wood
Top achievements
Rank 1
Nick Wood asked on 24 Apr 2011, 12:03 PM
Hi All
Have followed the same on drag drop and would like to prevent the payload from being removed from the source collection.

I have implemented the Behavior in ListBoxDragDropBehaviour and removed the onComplete code that would remove the payload item from the source:
(payload.SourceAppointmentsSource as IList).RemoveAll((object i) => payload.DraggedAppointments.Cast<object>().Contains(i));
But it does not even call the code in the
e.Options.Status == DragStatus.DropComplete
yet it still removes the payload item from the source.

Where else could I be missing the code that is doing this?

Nick

10 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 25 Apr 2011, 08:20 AM
Hello Nick,

This is a strange behavior. The code that you removed should be enough to implement the task. Is it possible to send us your project and review it? This will help us understand what is the difference with our demo and find the source of the problem.

All the best,
Rosi
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Nick Wood
Top achievements
Rank 1
answered on 26 Apr 2011, 12:04 AM
Hi Rosi

The project is to large to put all of the code here, but the portion that I am testing is exactly the same code as your example drag/drop: http://demos.telerik.com/silverlight/#ScheduleView/DragDrop

In this example, it removes the source list item when dropped, I thought it was the line of code that I removed that would have removed the source item, but it was not. you can test in your source code for this example and you will see that there is something else causing the source item to be removed. I have had a thorough look and all I can think is that is must be in the the OnDrop event of the schedule view in the source code.

Nick
0
Rosi
Telerik team
answered on 03 May 2011, 09:30 AM
Hello Nick,

Removing the code prevent removing of appointments when dragging from ScheduleView to ListBox. Please see the attached movie. The only change that I did to example was removing the described line of code. I suggest you send us your sample project to test it locally .This will help us find out the reason for the problem at your project.


If you want to prevent removing the items from ListBox when dragging to ScheduleView I suggest you implement a custom drag drop behavior and override its Drop method as shown below. The custom class is also attached to this message.
public class CustomDragDrop : DefaultDragDropBehavior
    {
        public override void Drop(DragDropState state)
        {
            if (state.SourceAppointmentsSource == state.DestinationAppointmentsSource)
            {
                base.Drop(state);
            }
            else
            {
                var appointmentToAdd = state.Appointment as Appointment;
                appointmentToAdd.Start = state.DestinationSlots.First().Start;
                appointmentToAdd.End = state.DestinationSlots.First().End;
                (state.DestinationAppointmentsSource as ObservableCollection<Appointment>).Add(appointmentToAdd);
            }
  
        }
    }

XAML
<telerik:RadScheduleView x:Name="ScheduleView" Grid.Column="2" AppointmentsSource="{Binding Appointments}"
                ActiveViewDefinitionIndex="1">
            <telerik:RadScheduleView.DragDropBehavior>
                <local:CustomDragDrop/>
            </telerik:RadScheduleView.DragDropBehavior>
            <telerik:RadScheduleView.ViewDefinitions>
                <telerik:DayViewDefinition />
                <telerik:WeekViewDefinition />
                <telerik:MonthViewDefinition />
                <telerik:TimelineViewDefinition />
            </telerik:RadScheduleView.ViewDefinitions>
        </telerik:RadScheduleView>

Kind regards,
Rosi
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 2
answered on 17 May 2011, 06:50 AM
Do you have to override the default drag and drop in order to get drag and drop working with ScheduleView?

I've tried putting telerik:RadDragAndDropManager.AllowDrop="true" on my RadScheduleView but I never get anything other than DropImpossible in my OnDropInfo. Where do I tell it that it's ok to use the RadScheduleView as a drop target? I've pretty much switched from the RadSchedule over to the RadScheduleView where i had drag and drop working with the former, but now can't seem to get the ScheduleView to DropAllow.

Do I have to customise the drag and drop and tell it Drop is allowed in that? Or does the default drag and drop work?

Is there an example around that doesn't use the ListBoxDrag and Drop Behaviour? I don't want to use that.

thanks,
Stephen
0
Stephen
Top achievements
Rank 2
answered on 17 May 2011, 09:13 AM
Hi,

I've just come across this issue myself and have found that by decompiling with Reflector and stepping through the code it's the default behaviour of the Drop method in the DefaultDragDropBehaviour class.

this bit of code here

 else if (appointment != null)
          {
            IList sourceAppointmentsSource = state.SourceAppointmentsSource as IList;
            this.CopyAppointment(state, targetSlot, appointment);
            if (!state.IsControlPressed && (sourceAppointmentsSource != null))
            {
              sourceAppointmentsSource.Remove(appointment);
            }
          }

basically removes the appointment from the source if the control key is not pressed.

A solution to this would be to use a CustomDefaultDragDropBehaviour and modify it to not remove the appointment.

cheers,
Stephen
0
Yana
Telerik team
answered on 20 May 2011, 09:31 AM
Hi Stephen,

Please check the other forum thread regarding same issue here.

All the best,
Yana
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Jaime Bula
Top achievements
Rank 2
answered on 25 Jul 2011, 03:55 AM
0
Yana
Telerik team
answered on 27 Jul 2011, 08:58 AM
Hi Jaime,

We removed the sample intentionally as there is a problem with the drag and drop from ListBox to ScheduleView. The issue will be fixed for the service pack in September.  Please send us more details about your scenario, so we to be able to provide a work-around. Thanks in advance

Kind regards,
Yana
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Kotte
Top achievements
Rank 1
answered on 31 Aug 2011, 06:43 PM
Hi Yana,

Can you please post a sample project with basic DragDrop functionality working.
I tried to create a  CustomDragDropBehavior and override CanDrop and  Drop methods and its not doing any thing.
is DragDrop going fire AppointmentEditing event??

 <telerik:RadScheduleView.DragDropBehavior>
                <Calendar:CustomDragDropBehavior></Calendar:CustomDragDropBehavior>
   </telerik:RadScheduleView.DragDropBehavior>

public class CustomDragDropBehavior : ScheduleViewDragDropBehavior 
    {
        public override bool CanDrop(DragDropState state)
        {
            return true;
        }


        public override bool CanStartDrag(DragDropState state)
        {
            return true;
        }


        public override void Drop(DragDropState state)
        {
            base.Drop(state);
        }
    }
0
Yana
Telerik team
answered on 01 Sep 2011, 09:05 AM
Hello Kotte,

Please check this forum post the Drag/Drop from ListBox to RadScheduleView is explained in more details.

Kind regards,
Yana
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
ScheduleView
Asked by
Nick Wood
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Nick Wood
Top achievements
Rank 1
Stephen
Top achievements
Rank 2
Yana
Telerik team
Jaime Bula
Top achievements
Rank 2
Kotte
Top achievements
Rank 1
Share this question
or