Making single Appointments read-only

14 posts, 0 answers
  1. AMF
    AMF avatar
    34 posts
    Member since:
    Mar 2011

    Posted 24 Oct 2011 Link to this post

    Hello,

    I have a class that inherits from Telerik.WinControls.UI.Appointment. After clicking a checkbox on the edit-dialog of said appointment subclass and clicking OK, I need this single appointment to be read-only.

    I have tried setting the AllowDelete and AllowEdit properties of the Appointment to false, which does the trick with regard to blocking the delete-button and preventing the edit-dialog from opening. However, I can still 'resize' and drag an appointment that is on/inside the Scheduler. Is there a way to prevent that, i.e. make this one Appointment perfectly read-only?

    Thanks in advance for your answer.
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 27 Oct 2011 Link to this post

    Hi Amf,

    Thank you for contacting us.

    There is a way you can cancel appointments' resizing or moving. The following code snippet demonstrates which events to use in order to achieve this:
    this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(DragDropBehavior_AppointmentMoving);
     
    this.radScheduler1.SchedulerElement.ResizeBehavior.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(ResizeBehavior_AppointmentResizing);
     
    this.radScheduler1.ActiveViewChanged += new EventHandler<SchedulerViewChangedEventArgs>(radScheduler1_ActiveViewChanged);
     
    void radScheduler1_ActiveViewChanged(object sender, SchedulerViewChangedEventArgs e)
    {
        this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(DragDropBehavior_AppointmentMoving);
     
        this.radScheduler1.SchedulerElement.ResizeBehavior.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(ResizeBehavior_AppointmentResizing);
    }
     
    void ResizeBehavior_AppointmentResizing(object sender, AppointmentResizingEventArgs e)
    {
        e.Cancel = true;
    }
     
    void DragDropBehavior_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
        e.Cancel = true;
    }

    In addition, I would like to mention that in the next official release we are going to expose these events directly to the RadScheduler control. This will let you easily handle such scenarios.

    I hope this is useful. Feel free to write back if you have any additional questions.

    Greetings,
    Ivan Todorov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. AMF
    AMF avatar
    34 posts
    Member since:
    Mar 2011

    Posted 27 Oct 2011 Link to this post

    Hello Ivan,

    Thank you for your answer. I have succesfully implemented your solution which prevents dragging and resizing of appointments. The only problem I still encounter is the dragging of Appointments which are larger than the schedule window.

    When that happens (dragging a large appointment), the code gets to the e.Cancel line in the Moving event, but because the appointment is too large, the Scheduler window scrolls by itself, which still makes the appointment move.

    Any thoughts on this? Is there a way to also cancel any scrolling events that are triggered by the Appointment moving?
  5. AMF
    AMF avatar
    34 posts
    Member since:
    Mar 2011

    Posted 27 Oct 2011 Link to this post

    Upon closer inspection, I ran into some problems: I can still move the appointment. Any thoughts on this?
  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 28 Oct 2011 Link to this post

    Hello Amf,

    Thank you for writing back.

    I was able to identify some cases in which the code I have provided does not work. Please try canceling the AppointmentDropping event as well as it is shown in the following snippet:
    this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(DragDropBehavior_AppointmentMoving);
     
    this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentDropping += new EventHandler<AppointmentMovingEventArgs>(DragDropBehavior_AppointmentDropping);
     
    this.radScheduler1.SchedulerElement.ResizeBehavior.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(ResizeBehavior_AppointmentResizing);
     
    this.radScheduler1.ActiveViewChanged += new EventHandler<SchedulerViewChangedEventArgs>(radScheduler1_ActiveViewChanged);
     
    void radScheduler1_ActiveViewChanged(object sender, SchedulerViewChangedEventArgs e)
    {
        this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(DragDropBehavior_AppointmentMoving);
     
        this.radScheduler1.SchedulerElement.DragDropBehavior.AppointmentDropping += new EventHandler<AppointmentMovingEventArgs>(DragDropBehavior_AppointmentDropping);
     
        this.radScheduler1.SchedulerElement.ResizeBehavior.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(ResizeBehavior_AppointmentResizing);
    }
     
    void DragDropBehavior_AppointmentDropping(object sender, AppointmentMovingEventArgs e)
    {
        e.Cancel = true;
    }
     
    void ResizeBehavior_AppointmentResizing(object sender, AppointmentResizingEventArgs e)
    {
        e.Cancel = true;
    }
     
    void DragDropBehavior_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
        e.Cancel = true;
    }

    Please note that this code will not work in grouped by resource views, since the DragDropBehavior is not used for dragging between resources. I would suggest switching to the new version when it is available, since the events we are going to introduce should cover all cases.

    I hope you find this useful. Should you have additional questions, do not hesitate to ask.

    Greetings,
    Ivan Todorov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  7. AMF
    AMF avatar
    34 posts
    Member since:
    Mar 2011

    Posted 28 Oct 2011 Link to this post

    Hello Ivan,

    Thank you for your reply. We are currently working with ResourceViews, so is there a workaround to solve said problem?
  8. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 01 Nov 2011 Link to this post

    Hi Amf,

    It appears that I have mistaken the versions and the events you need are already in the version you are using. The following code snippet demonstrates how to use them:
    this.radScheduler1.AppointmentMoving += new EventHandler<AppointmentMovingEventArgs>(radScheduler1_AppointmentMoving);
    this.radScheduler1.AppointmentResizing += new EventHandler<AppointmentResizingEventArgs>(radScheduler1_AppointmentResizing);
    this.radScheduler1.AppointmentDropping += new EventHandler<AppointmentMovingEventArgs>(radScheduler1_AppointmentDropping);
     
    void radScheduler1_AppointmentDropping(object sender, AppointmentMovingEventArgs e)
    {
        e.Cancel = true;
    }
      
    void radScheduler1_AppointmentResizing(object sender, AppointmentResizingEventArgs e)
    {
        e.Cancel = true;
    }
     
    void radScheduler1_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
        e.Cancel = true;
    }

    Please excuse me for any inconveniences caused. I hope this is useful.

    If you have any additional questions, do not hesitate to ask.

    Regards,
    Ivan Todorov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  9. AMF
    AMF avatar
    34 posts
    Member since:
    Mar 2011

    Posted 23 Nov 2011 Link to this post

    Dear Ivan,

    The events are available now, thank you for your help with that.
    Now I have implemented them like this;
    void rdSchedule_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
       e.Cancel = (!e.Appointment.AllowEdit);
    }
      
    void rdSchedule_AppointmentDropping(object sender, AppointmentMovingEventArgs e)
    {
       e.Cancel = (!e.Appointment.AllowEdit);
    }
      
    void rdSchedule_AppointmentResizing(object sender, AppointmentResizingEventArgs e)
    {
       e.Cancel = (!e.Appointment.AllowEdit);
    }

    There is something strange about this. We have created our own inheritance of the Appointment object and fill the Allow Edit according to our needs.
    Here comes the weird thing: In the Moving and Dropping events the Appointment object is not our inherited object (and thus AllowEdit is true) but when the AppointmentResizing event is fired it is our inherited object and the Appointment cannot be edited.

    Am I missing something here?
  10. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 25 Nov 2011 Link to this post

    Hi Amf,

    Thank you for contacting us.

    This appears to be an issue in the drag&drop functionality of RadScheduler. It has already been reported by another client and we are currently working on it. Most probably, it will be addressed in the next official release. Here is the PITS item I have created about the previously reported issue. It concerns the DataItem property, but the reason which is causing it is that the e.Appointment is actually a different object, which is your case. You can subscribe to this PITS item to track its progress.

    Meanwhile, I can suggest the following workaround which uses reflection to get the original appointment:
    void radScheduler1_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
        SchedulerDayViewGroupedByResourceElement dayViewElement = (this.radScheduler1.SchedulerElement.ViewElement as SchedulerDayViewGroupedByResourceElement);
        SchedulerMonthViewGroupedByResourceElement monthViewElement = (this.radScheduler1.SchedulerElement.ViewElement as SchedulerMonthViewGroupedByResourceElement);
        TimelineGroupingByResourcesElement timelineViewElement = (this.radScheduler1.SchedulerElement.ViewElement as TimelineGroupingByResourcesElement);
     
        if (dayViewElement != null)
        {
            FieldInfo fi = dayViewElement.GetType().GetField("originalDraggingAppointment", BindingFlags.NonPublic | BindingFlags.Instance);
            Appointment originalAppointment = (Appointment)fi.GetValue(dayViewElement);
        }
        else if (monthViewElement != null)
        {
            FieldInfo fi = monthViewElement.GetType().GetField("originalDraggingAppointment", BindingFlags.NonPublic | BindingFlags.Instance);
            Appointment originalAppointment = (Appointment)fi.GetValue(monthViewElement);
        }
        else if (timelineViewElement != null)
        {
            FieldInfo fi = timelineViewElement.GetType().GetField("_originalDraggingAppointment", BindingFlags.NonPublic | BindingFlags.Instance);
            Appointment originalAppointment = (Appointment)fi.GetValue(timelineViewElement);
        }
    }

    Do not hesitate to write back if you have any further questions.

    Regards,
    Ivan Todorov
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  11. Georgios
    Georgios avatar
    4 posts
    Member since:
    May 2013

    Posted 10 Jun 2013 Link to this post

    Hi,

    How would you prevent single appointment moving.
    I implemented the e.Cancel but when i try to drag the appointment it "disappears" as long as i have my mousebutton down.
    I should like to have "no behavior"

    I can see the Issue is from 2011 and you were hinting a different implementation.
    So, how should this be implemented today (2013)  :)

    private void radScheduler1_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
            {
                e.Cancel = true;
            }

    Thnaks in advance
    Georgios
  12. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 13 Jun 2013 Link to this post

    Hi Georgios,

    The observed behavior is caused because a drag operation is initiated. You can try calling the Stop method of the drag and drop service to prevent it :
    void radScheduler1_AppointmentMoving(object sender, AppointmentMovingEventArgs e)
    {
        radScheduler1.SchedulerElement.DragDropBehavior.Stop(true);
        e.Cancel = true;
    }
     
    I hope this helps.

    Regards,
    Stefan
    Telerik
    RadChart for WinForms is obsolete. Now what?
  13. Georgios
    Georgios avatar
    4 posts
    Member since:
    May 2013

    Posted 13 Jun 2013 Link to this post

    Hi,

    It still "disapears" when I click on it
    (It reappears when i leave the timeslot)

    Regards,
    Georgios
  14. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 18 Jun 2013 Link to this post

    Hello,

    In this case you can try stopping the whole drag drop service:
    radScheduler1.DragDropBehavior.Starting += DragDropBehavior_Starting;
    .........
    void DragDropBehavior_Starting(object sender, RadServiceStartingEventArgs e)
    {
        e.Cancel = true;
    }

    I hope this helps.

    Regards,
    Stefan
    Telerik
    RadChart for WinForms is obsolete. Now what?
  15. Georgios
    Georgios avatar
    4 posts
    Member since:
    May 2013

    Posted 19 Jun 2013 Link to this post

    Thanks.

    Seems to work :)
    Georgios
Back to Top
UI for WinForms is Visual Studio 2017 Ready