How to create Recurring Appointments in SfSchedule?
Recurrence feature in the SfSchedule control is used to create recurring appointments. This article explains how to create recurring appointments with a time interval of two days.
Creating Recurring Appointments
- Create an appointment by using the following code example.
C#
ScheduleAppointment appointment = new ScheduleAppointment(); appointment.Subject = "Team Meeting"; appointment.Notes = "Daily Recurrence"; appointment.Location = "Meeting Hall 1"; appointment.StartTime = DateTime.Now.SubractDays(11); appointment.EndTime = DateTime.Now.SubractDays(11).AddHours(4); appointment.AppointmentBackground = new SolidColorBrush( (Color.FromArgb(0xFF, 0xD8, 0x00, 0x73)));
- Now, generate Recurrence rule by using RRuleGenerator and assign it to the RecurrenceRule property of the above created appointment as illustrated in the following code example.
Note: The RRuleGenerator method is used to create Rule available in the ScheduleHelper class.
C#
RecurrenceProperties RecProp = new RecurrenceProperties() //Specifying Recurrence type. RecProp.RecurrenceType = RecurrenceType.Daily; //Enabling EveryNDays RecProp.IsDailyEveryNDays = true; //Specifying the interval of 2 days RecProp.DailyNDays = 2; //Enabling the Range count specification RecProp.IsRangeRecurrenceCount = true; //Disabling the No end date RecProp.IsRangeNoEndDate = false; //Disabling the end date RecProp.IsRangeEndDate = false; //Specifying the range count RecProp.RangeRecurrenceCount = 100; appointment.RecurrenceRule = ScheduleHelper.RRuleGenerator(RecProp, appointment.StartTime, appointment.EndTime);
- In the above code example, recurrence rule is created for generating recurring appointments every 2 days. Now, set the IsRecursive property of the Scheduleappointment to true and add the created appointment to the schedule’s Appointments property as illustrated in the following code.
C#
app.IsRecursive = true; schedule.Appointments.Add(app);
The following screenshots display the output in different views.
Figure 1: Recurring appointments with time intervals of two days in the Month View
Figure 2: Recurring appointments with time intervals of two days in the Week view
Figure 3: Recurring appointments with time intervals of two days in the Day view
Figure 4: Recurring appointments with time intervals of two days in the TimeLine view