Drag and drop and snap to predefined time

2 posts, 0 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 15 Jan 2014 Link to this post

    Hi there!

    I'm building a staffing application.
    I have a ScheduleView with a DayViewDefinition. Outside of the schedule I have a ListBox with appointments that are predefined in time.
    The user drag an appointment and drop it on the schedule on a specific person (it's grouped on resources).
    The appointment will now be saved on that person with the predefined time, regardless of where in time it was dropped.

    This works fine for me, since I don't care about where it is dropped.
    But it looks strange to the user, since he can drop the appointment at for example 8:00 AM, but it actually ends up at 9:00 AM.
    Is there any way I can snap the appointment to the predefined time when I'm dragging it over the schedule?


    Regards,
    Håkan

  2. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 17 Jan 2014 Link to this post

    Hi Håkan,

    You could achieve the desired behavior using the ScheduleView DragDropBehavior. You could either override the CanDrop method in order to check if the DestinationSlot is the required one and if not to prevent the drop. Or you could modify the already dropped Appointment by overriding the DragDropCompleted method and change the Start and the End of the Appointment as required. Here is a sample solution of the second scenario:

    public override void DragDropCompleted(DragDropState state)
    {
        var appointment = state.Appointment as CustomAppointment;
        var scheduleView = state.ServiceProvider.GetService<IDialogProvider>() as RadScheduleView;
     
        scheduleView.BeginEdit(appointment);

          // set the required times
        appointment.Start = appointment.Start.AddHours(1);
        appointment.End = appointment.End.AddHours(1);
        scheduleView.Commit();
     
        base.DragDropCompleted(state);
    }

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
Back to Top