New to Telerik UI for WinFormsStart a free 30-day trial

Minutely Recurrence Pattern in RadScheduler

Updated over 6 months ago

Environment

Product Version2021.3.914
ProductRadScheduler for WinForms

Description

When the recurrence dialog is open, the dialog provides the following recurrence patterns: Hourly, Daily, Weekly, Monthly, Yearly. This KB article demonstrates how we can add a minutely recurrent pattern. The custom class needs to implement IRecurrenceRuleSettingsControl interface.

Solution

Create a custom UserControl which will hold the options to set the minutes. In the following example, we will the same structure of the Hourly UserControl which contains one RadSpinEditor and two labels.

Custom UserControl

C#
public partial class MinutelyRecurrenceSettings : UserControl, IRecurrenceRuleSettingsControl
{
    private ISchedulerData schedulerData;
    public MinutelyRecurrenceSettings()
        : this(null) { }

    public MinutelyRecurrenceSettings(ISchedulerData schedulerData)
    {
        this.schedulerData = schedulerData;
        InitializeComponent();
    }

    public bool CanShowRecurrenceRule(RecurrenceRule recurrenceRule)
    {
        return recurrenceRule.Frequency == RecurrenceType.Minutely;
    }

    public RecurrenceRule GetRecurrenceRule()
    {
        MinutelyRecurrenceRule rule = new MinutelyRecurrenceRule();
        rule.Interval = (int)this.spinInterval.Value;
        return rule;
    }

    public bool IsValidRecurrenceRule()
    {
        return true;
    }

    public void ShowRecurrenceRule(RecurrenceRule recurrenceRule, CultureInfo culture)
    {
        this.spinInterval.Value = recurrenceRule.Interval;
    }
}

The next part is to create custom EditRecurrenceDialog in which we are going to add a new RadRadioButton and set the UserControl related to it. To show the custom UserControl we need to subscribe to the ToggleChanged event of the control and call the ShowRecurrenceSettingsControl() which will hide the previous one and show the new content. The rest of the radio buttons need to be re-arranged to make space for the Minutely RadRadioButton.

What's left to do is to replace the default EditRecurrenceDialog with our custom dialog inside the RecurrenceEditDialogShowing event handler of the RadScheduler control.

Form`s Class

C#
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
	public RadForm1()
	{
		InitializeComponent();
		this.radScheduler1.RecurrenceEditDialogShowing += radScheduler1_RecurrenceEditDialogShowing;
	}

	void radScheduler1_RecurrenceEditDialogShowing(object sender, RecurrenceEditDialogShowingEventArgs e)
	{
		e.RecurrenceEditDialog = new MyRecurrenceDialog(e.Appointment, this.radScheduler1);
	}        
}
public class MyRecurrenceDialog : EditRecurrenceDialog
{
	RadRadioButton radioMinutely = new RadRadioButton();
	public MyRecurrenceDialog(IEvent appointment, ISchedulerData schedulerData)
		: base(appointment, schedulerData)
	{
		this.radioMinutely.Location = new System.Drawing.Point(7, 20);
		this.radioMinutely.Name = "radioMinutely";
		this.radioMinutely.Size = new System.Drawing.Size(50, 18);
		this.radioMinutely.TabIndex = 3;
		this.radioMinutely.Text = "Minute";
		recurrenceGroupBox.Size = new Size(recurrenceGroupBox.Size.Width, recurrenceGroupBox.Size.Height + 50);
		this.recurrenceGroupBox.Controls.Add(this.radioMinutely);
		this.radioMinutely.ToggleStateChanged += RadioMinutely_ToggleStateChanged;
		this.radioHourly.Location = new Point(this.radioHourly.Location.X, this.radioHourly.Location.Y + 15);
		this.radioDaily.Location = new Point(this.radioDaily.Location.X, this.radioDaily.Location.Y + 15);
		this.radioWeekly.Location = new Point(this.radioWeekly.Location.X, this.radioWeekly.Location.Y + 15);
		this.radioMonthly.Location = new Point(this.radioMonthly.Location.X, this.radioMonthly.Location.Y + 15);
		this.radioYearly.Location = new Point(this.radioYearly.Location.X, this.radioYearly.Location.Y + 15);
	}

	private void RadioMinutely_ToggleStateChanged(object sender, StateChangedEventArgs args)
	{
		RadRadioButton radioButton = sender as RadRadioButton;
		IRecurrenceRuleSettingsControl settingsControl = this.radioToSettingsDictionary[radioButton];
		this.ShowRecurrenceSettingsControl(settingsControl);
		settingsControl.ShowRecurrenceRule(this.recurrenceRule, this.culture);
	}

	protected override void CreateRadioToSettingsDictionary()
	{
		base.CreateRadioToSettingsDictionary();
		MinutelyRecurrenceSettings minuteRecurrenceSettings = new MinutelyRecurrenceSettings(this.schedulerData);
		this.radioToSettingsDictionary.Add(radioMinutely, minuteRecurrenceSettings);
	}
}

scheduler-minutely-recurrence-pattern 001

See Also