How to: Create a Custom Appointment Recurrence Form (Method 2)
- 9 minutes to read
This document describes how to create a custom form and replace the standard appointment recurrence editing form with a newly created form. Method 2 uses the System.Windows.Forms.Form and the AppointmentFormController.
To create a custom form, add a new form to the project and name it MyAppointmentRecurrentForm.
There are six recurrence types (refer to the RecurrenceType topic) and four ready-to-use recurrent controls suitable for most situations. To add required controls to the form, perform the following steps:
- Select the GroupControl in the Toolbox and drop it onto the MyAppointmentRecurrentForm. Change its visibility to false.
- Drag the DailyRecurrenceControl from the Toolbox and drop it on the GroupControl. Place it over the previous control. Change its visibility to false.
- Drag the WeeklyRecurrenceControl from the Toolbox and drop it on the GroupControl. Place it over the previous control. Change its visibility to false.
- Drag the MonthlyRecurrenceControl from the Toolbox and drop it on the GroupControl. Place it over the previous control. Change its visibility to false.
- Drag the YearlyRecurrenceControl from the Toolbox and drop it on the GroupControl. Place it over the previous control. Change its visibility to false.
- Select the RadioGroup control in the Toolbox and drop it on the form. Add four items to the control with the RadioGroupItem.Description values set to Daily, Weekly, Monthly and Yearly. Specify these strings as the RadioGroupItem.Value property values.
- Add OK and Cancel buttons.
The form will look like that shown in the following picture.
Add the code to the code behind file as illustrated in the following example.
The code below is an example of the custom recurrent appointment editing form. Invoke it for recurring appointments. This form allows changing recurrence options only. To change start/end times and durations, add other controls to the form.
Handle the SchedulerControl.EditAppointmentFormShowing event to invoke a custom form instead of the default AppointmentForm.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-create-a-simple-recurrence-form-t222451
- Program.cs
- MyAppointmentRecurrenceForm.cs
- Form1.cs
- MyAppointmentRecurrenceForm.vb
- Form1.vb
- Program.vb
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CustomRecurrenceFormWinFormSample
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Some comments are given below to clarify the interaction logic.
- To edit an appointment, the AppointmentFormController object is required. Use its AppointmentModificationControllerBase.PrepareToRecurrenceEditmethod, to obtain a copy of the recurrence pattern for this appointment. All changes are applied to the appointment’s copy only. The AppointmentModificationControllerBase.ApplyRecurrence method should be called to alter an instance of the appointment recurrence pattern. To send the changes back to the original instance of the appointment, call the AppointmentModificationControllerBase.ApplyChanges method.
- Since several recurrence controls refer to week days, select the first day of the week for their proper initialization. The first day of the week setting is a scheduler option, available via SchedulerOptionsViewBase.FirstDayOfWeek.
- The recurrence controls are linked to the RecurrenceInfo object. To display changes of this object, call the corresponding RecurrenceControlBase.UpdateControls method of the control.
- The code example contains DevExpress.XtraScheduler.Native.DateTimeHelper methods. This is an internal object, used for the date-time type conversion. In your code, you can utilize another methods for the type conversion.
- When the user clicks “OK”, the control’s edited values are validated by calling the RecurrenceControlBase.ValidateValues method. This method is specific to a control, and usually checks whether the value is a positive integer, not more than 31, whether it’s a day number and so on. In case of any problem, a dialog window is displayed. Some settings may have side effects, so the RecurrenceControlBase.CheckForWarnings procedure is called, to show warnings to the user.