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

Recurrence Items

8 Answers 218 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
Jeremy Murtishaw
Top achievements
Rank 1
Jeremy Murtishaw asked on 19 Aug 2009, 12:03 AM
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.

8 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 21 Aug 2009, 08:26 AM
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.
0
Jeremy Murtishaw
Top achievements
Rank 1
answered on 21 Aug 2009, 05:27 PM
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()
        { }
    }
0
Jordan
Telerik team
answered on 24 Aug 2009, 12:45 PM
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.
0
Stephen
Top achievements
Rank 1
answered on 13 Jan 2011, 05:07 PM
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
0
Dobry Zranchev
Telerik team
answered on 18 Jan 2011, 05:51 PM
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.
0
Timothy
Top achievements
Rank 1
answered on 23 Apr 2013, 01:34 AM
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.
0
Timothy
Top achievements
Rank 1
answered on 23 Apr 2013, 01:45 AM
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.
0
Peter
Telerik team
answered on 25 Apr 2013, 01:01 PM
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.
Tags
Scheduler and Reminder
Asked by
Jeremy Murtishaw
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jeremy Murtishaw
Top achievements
Rank 1
Jordan
Telerik team
Stephen
Top achievements
Rank 1
Dobry Zranchev
Telerik team
Timothy
Top achievements
Rank 1
Peter
Telerik team
Share this question
or