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

Prevent all day appointment being created

1 Answer 31 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 11 Sep 2013, 09:32 AM
How do I go about prevent all day appointments being created. If I create an appointment in the scheduler as normal and drag it to the top of the scheduler into the all day bar it changes the times to an all day event. I want to prevent them double clicking in the all day event bar or dragging and dropping an appointment in to this bar.

I've tried the following but it still allows me to create appointments
void rsTest_CellFormatting(object sender, SchedulerCellEventArgs e)
      {
          if (e.CellElement is SchedulerHeaderCellElement)
          {
              e.CellElement.Enabled = false;
              e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
          }
      }

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 16 Sep 2013, 08:48 AM
Hello Karl,

Thank you for writing.

You can prevent all day appointments from being created by subscribing to the CollectionChanged event of the Appointments collection of the RadScheduler:
this.scheduler.Appointments.CollectionChanging += Appointments_CollectionChanging;

The event handler looks like this:
void Appointments_CollectionChanging(object sender, NotifyCollectionChangingEventArgs e)
{
    if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems.Count > 0)
    {
        Appointment newApp = e.NewItems[0] as Appointment;
        if (this.IsAllDayAppointment(newApp))
        {
            e.Cancel = true;
        }
    }
}

The method for checking if the given appointment is all day event is this:
private bool IsAllDayAppointment(Appointment app)
{
    if ((app.Start.Minute == 0 && app.Start.Hour == 0 && app.Start.Second == 0) &&
        (app.End.Minute == 59 && app.End.Hour == 23 && app.End.Second == 59))
    {
        return true;
    }
 
    return false;
}

I hope this helps. For any further questions, do not hesitate to ask.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
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 >>
Tags
Scheduler and Reminder
Asked by
Karl
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or