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

Adding an exception programmatically

4 Answers 143 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 03 Jan 2013, 10:06 PM
Would it be possible to get a code sample in C# of adding an exception with visible set to false to a recurring appointment?  I can't seem to get it to work in my project and I can't find any clear cut examples anywhere.

Thanks,
Matt

4 Answers, 1 is accepted

Sort by
0
Matt
Top achievements
Rank 1
answered on 07 Jan 2013, 09:36 PM
Any help would be appreciated!
0
Ivan Todorov
Telerik team
answered on 08 Jan 2013, 10:18 AM
Hello Matt,

Thank you for your question.

Here is how you can get the third occurrence and add it as an exception with Visible = false:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.radScheduler1.Appointments.Add(new Appointment(DateTime.Now, DateTime.Now.AddHours(1), "RecurringAppointment"));
        this.radScheduler1.Appointments[0].RecurrenceRule = new DailyRecurrenceRule();
    }
 
    private void radButton1_Click(object sender, EventArgs e)
    {
        int index = 0;
        IEvent ev = null;
        foreach (IEvent occurence in this.radScheduler1.Appointments[0].Occurrences)
        {
            ev = occurence;
            index++;
            if (index == 3)
            {
                break;
            }
        }
 
        if (ev != null)
        {
            ev.Visible = false;
            ev.MasterEvent.Exceptions.Add(ev);
        }
    }
}

I hope you find this useful. Do not hesitate to ask if you have any other questions.

All the best,
Ivan Todorov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Matt
Top achievements
Rank 1
answered on 08 Jan 2013, 05:47 PM
Hmmm.. I keep getting the same odd behavior.

Instead of setting the appointment to be non-visible, it will set all occurrences prior to the date of the exception I'm trying to add to non-visible, and then will append that number of occurrences to the front of the occurrences.

So, for example, say I have an appointment on 1/20/2013 that recurs every day for five occurrences (1/20/2013 - 1/24/2013 inclusive).  If I try to add an exception for 1/22/2013, the appointments for 1/20/2013 and 1/21/2013 will disappear, and two new appointments will appear for 1/25/2013 and 1/26/2013.

I assume somehow the MasterEvent is being set to the date of the exception I'm trying to add, but I do nothing of the sort in my code...

I pass in a datetime (dt) and an appointment (appt) and then use that datetime to find the specific occurrence in the appointment that the user is referring to:

IEvent ev = null;
  
 foreach (IEvent e in appt.Occurrences)
{
    if (((Appointment)e).Start.Date == dt.Date)
    {
        ev = e;
        ev.Visible = false;
        ev.MasterEvent.Exceptions.Add(ev);
    }
}
0
Ivan Todorov
Telerik team
answered on 10 Jan 2013, 02:13 PM
Hi Matt,

I am not sure what might be causing this behavior. I am attaching a sample project which demonstrates that it works correctly. If you continue to experience difficulties, you can open a new support ticket and send me a sample project which demonstrates them. This will let me investigate your case and provide you with further details.

Please let me know if I can assist you further.

All the best,
Ivan Todorov
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
Scheduler and Reminder
Asked by
Matt
Top achievements
Rank 1
Answers by
Matt
Top achievements
Rank 1
Ivan Todorov
Telerik team
Share this question
or