Recurrence Items

9 posts, 0 answers
  1. Jeremy Murtishaw
    Jeremy Murtishaw avatar
    86 posts
    Member since:
    Apr 2009

    Posted 18 Aug 2009 Link to this post

    How do you go about updating only 1 instance of a recurring appointment programmically?  Say I want to change the tooltip or background color of just the occurence highlighted rather than all occurences that exist.
  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 21 Aug 2009 Link to this post

    Hi Jeremy Murtishaw,

    Thank you for contacting us. If you have a recurrent appointment (for simplicity I am using Appointment[0] in the code below) which is repeated every day, you can access all its occurrences using the Occurrences property. Of course, this is an infinite sequence of Appointments so that the loop below will eventually throw stack overflow:

    private void radButton1_Click(object sender, EventArgs e) 
    {      
                foreach (Appointment appointment in this.radScheduler1.Appointments[0].Occurrences) 
                { 
     
                    appointment.ToolTipText = "Some tooltip text"
              
                } 


    Best wishes,
    Nick
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeremy Murtishaw
    Jeremy Murtishaw avatar
    86 posts
    Member since:
    Apr 2009

    Posted 21 Aug 2009 Link to this post

    I am using a custom Appointment Type (MyCustomAppointment).  I get the following error?  Any suggestions?

    Unable to cast object of type'Telerik.WinControls.UI.Appointment' to type 'MyCustomAppointment'.


    for (int i = 0; i < this.radScheduler.Appointments.Count; i++)
                {

                    foreach (MyCustomAppointment appointment in this.radScheduler.Appointments[i].Occurrences)
                    {
                       appointment.ToolTipText = "my tooltip";
                    }

                }



    public class MyCustomAppointment : Appointment
        {
            public MyCustomAppointment()
                : base()
            { }
        }
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 24 Aug 2009 Link to this post

    Hello Jeremy Murtishaw,

    The error that you get is because the objects are of type Appointment. This is because when a occurrence needs to be created the CreateOccurrence method is called. And in the Appointment class
    it is overridden to create objects of type Appointment:

     public override IEvent CreateOccurrence(DateTime start) 
            { 
                Appointment occurrence = new Appointment(); 
                occurrence.Start = start; 
                occurrence.Duration = this.Duration; 
                occurrence.Summary = this.Summary; 
                occurrence.Description = this.Description; 
                occurrence.Location = this.Location; 
                occurrence.ToolTipText = this.ToolTipText; 
                occurrence.Visible = this.Visible; 
                occurrence.AllowDelete = this.AllowDelete; 
                occurrence.AllowEdit = this.AllowEdit; 
                occurrence.resourceIds = this.resourceIds; 
                occurrence.BackgroundId = this.BackgroundId; 
                occurrence.StatusId = this.StatusId; 
                occurrence.IsViewCalculated = true
                occurrence.masterEvent = this
                occurrence.CultureInfoProvider = this.CultureInfoProvider; 
     
                return occurrence; 
            } 

    In order to avoid the error you must override this method in your custom appointment class and implement it to create instances of MyCustomAppointment type instead of the Appointment type.
     
    However, if you do not have custom fields or logic (i.e. you do not need a custom appointment class) you can just use the IEvent type in your code as RadScheduler does.

    Sincerely yours,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Stephen
    Stephen avatar
    4 posts
    Member since:
    May 2009

    Posted 13 Jan 2011 Link to this post

    Hi Jordan,
         I was having this same problem aswell, except that my application is written in VB. I have a custom class that inherits from Appointment class. After reading some other threads I have added a shadow property for Master Event, as this field does not have a setter in the base class. This works fine, the only thing that does not work is that when the recurrence appointments are displayed on the scheduler window, the recurrence icon only appears on the original first occurence, and not on the other occurences which it does if you do not use a custom appointment class. Is this a bug or am I missing something else in my custom class ?.

        Private _masterEvent As Telerik.WinControls.UI.IEvent
        Public Shadows ReadOnly Property MasterEvent() As Telerik.WinControls.UI.IEvent
            Get
                If Object.Equals(_masterEvent, Nothing) Then
                    Return Nothing
                Else
                    Return _masterEvent
                End If
            End Get
        End Property

    ''' <
    summary>  
    ''' ... for repeated occurrences   
    ''' </summary>  
    ''' <param name="start"></param>  
    ''' <returns></returns>  
    Public Overrides Function CreateOccurrence(ByVal start As Date) As IEvent
        Dim occurrence As OutlookLikeAppointment = New OutlookLikeAppointment
        occurrence.Start = start
        occurrence.Duration = Me.Duration
        occurrence.RecurrenceRule = Nothing
        occurrence.Summary = Me.Summary
        occurrence.Description = Me.Description
        occurrence.Location = Me.Location
        occurrence.ToolTipText = Me.ToolTipText
        occurrence.Visible = Me.Visible
        occurrence.AllowDelete = Me.AllowDelete
        occurrence.AllowEdit = Me.AllowEdit
        occurrence.ResourceIds = Me.ResourceIds
        occurrence.BackgroundId = Me.BackgroundId
        occurrence.StatusId = Me.StatusId
        occurrence.CultureInfoProvider = Me.CultureInfoProvider
        occurrence.IsViewCalculated = True
         occurrence.MasterEvent = Me
         occurence.Email = Me.Email
        Return occurrence
    End Function

    Many thanks

    Steve
  7. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 18 Jan 2011 Link to this post

    Hello Steve,

    Thank you for writing.

    You are correct that you are not able to set the MasterEvent of the occurrence. The reason is that the field and the property MasterEvent is called with the same name (field name is 'masterEvent', property name is 'MasterEvent'). VB.Net is not case sensitive and it finds only the property so you are not able to see the field. If you want to set this property, you should to use reflection in order to set the field value.
    Public Class CustomAppointment
     inherits Appointment
     
        ''' <summary> 
        ''' ... for repeated occurrences  
        ''' </summary> 
        ''' <param name="start"></param> 
        ''' <returns></returns> 
        Public Overrides Function CreateOccurrence(ByVal start As Date) As IEvent
            Dim occurrence As CustomAppointment = New CustomAppointment
            occurrence.Start = start
            occurrence.Duration = Me.Duration
            occurrence.RecurrenceRule = Nothing
            occurrence.Summary = Me.Summary
            occurrence.Description = Me.Description
            occurrence.Location = Me.Location
            occurrence.ToolTipText = Me.ToolTipText
            occurrence.Visible = Me.Visible
            occurrence.AllowDelete = Me.AllowDelete
            occurrence.AllowEdit = Me.AllowEdit
             
            For each id as EventId in Me.ResourceIds
                occurrence.ResourceIds.Add(id)
            Next
             
            occurrence.BackgroundId = Me.BackgroundId
            occurrence.StatusId = Me.StatusId
            occurrence.CultureInfoProvider = Me.CultureInfoProvider
            occurrence.IsViewCalculated = True
            dim appType as Type = GetType(Telerik.WinControls.UI.Appointment)
            appType.GetField("masterEvent", system.reflection.bindingFlags.Instance or system.reflection.bindingFlags.NonPublic).SetValue(occurrence, me)
            Return occurrence
        End Function
     
    End Class

    In case that you have other related questions, do not hesitate to write back.

    All the best,
    Dobry Zranchev
    the Telerik team
    Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
  8. Timothy
    Timothy avatar
    37 posts
    Member since:
    Nov 2012

    Posted 22 Apr 2013 Link to this post

    Is this still relevant?

    Dim appType As Type = GetType(Telerik.WinControls.UI.Appointment)
    appType.GetField("masterEvent", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic).SetValue(occurrence, Me)

    appType.GetField("masterEvent", System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.NonPublic) returns Nothing for me.

    Thanks.
  9. Timothy
    Timothy avatar
    37 posts
    Member since:
    Nov 2012

    Posted 22 Apr 2013 Link to this post

    I think I may have figured it out. The Appointment class inherits the Event class which contains masterEvent. So, I substituted Event for Appointment. Is that the correct way to do it now?

    Thanks.
  10. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 25 Apr 2013 Link to this post

    Hi Timothy,

    Thank you for writing.

    I would like to confirm that your approach is correct because the Appointment class inherits the Event class, which contains the MasterEvent property, which is read-only and cannot be set.

    Should you have any other questions or suggestions, do not hesitate to contact us.

    All the best,
    Peter
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top
UI for WinForms is Visual Studio 2017 Ready