Adding an exception programmatically

5 posts, 0 answers
  1. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 03 Jan 2013 Link to this post

    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
  2. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 07 Jan 2013 Link to this post

    Any help would be appreciated!
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 08 Jan 2013 Link to this post

    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.
  5. Matt
    Matt avatar
    24 posts
    Member since:
    Dec 2012

    Posted 08 Jan 2013 Link to this post

    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);
        }
    }
  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 10 Jan 2013 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready