Prevent removal from source collection on Drag/Drop

11 posts, 0 answers
  1. Nick Wood
    Nick Wood avatar
    126 posts
    Member since:
    Feb 2010

    Posted 24 Apr 2011 Link to this post

    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
  2. Rosi
    Admin
    Rosi avatar
    2529 posts

    Posted 25 Apr 2011 Link to this post

    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
  3. Nick Wood
    Nick Wood avatar
    126 posts
    Member since:
    Feb 2010

    Posted 25 Apr 2011 Link to this post

    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
  4. Rosi
    Admin
    Rosi avatar
    2529 posts

    Posted 03 May 2011 Link to this post

    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
  5. Stephen
    Stephen avatar
    40 posts
    Member since:
    Jul 2008

    Posted 17 May 2011 Link to this post

    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
  6. Stephen
    Stephen avatar
    40 posts
    Member since:
    Jul 2008

    Posted 17 May 2011 Link to this post

    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
  7. Yana
    Admin
    Yana avatar
    4713 posts

    Posted 20 May 2011 Link to this post

    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
  8. Jaime Bula
    Jaime Bula avatar
    45 posts
    Member since:
    Apr 2009
  9. Yana
    Admin
    Yana avatar
    4713 posts

    Posted 27 Jul 2011 Link to this post

    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!

  10. Kotte
    Kotte avatar
    48 posts
    Member since:
    Feb 2011

    Posted 31 Aug 2011 Link to this post

    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);
            }
        }
  11. Yana
    Admin
    Yana avatar
    4713 posts

    Posted 01 Sep 2011 Link to this post

    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 >>

Back to Top