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

Casting Problem..

2 Answers 146 Views
Scheduler and Reminder
This is a migrated thread and some comments may be shown as answers.
KocSchool
Top achievements
Rank 2
KocSchool asked on 20 Nov 2009, 11:44 AM
Hi,

I used Custom Field for scheduler control. And I watched Adding Custom Fields to RadScheduler for WinForms Appointments. And I read online help. I did it same things.

My problem,  

        It can't cast IEvent object to NewAppointmentObject on ApplySettingsToEvent.. NewAppointmentObject is inherited from Appointment Class.. Its code is following.

using System;  
using System.Collections.Generic;  
using System.Text;  
using Telerik.WinControls;  
using Telerik.WinControls.UI;  
 
namespace LearnRadScheduler  
{  
    public class NewAppointmentObject : Appointment  
    {  
        public NewAppointmentObject()  
            : base()  
        {  
 
        }  
 
        private string subjectEN = string.Empty;  
        public string SubjectEN  
        {  
            get { return this.subjectEN; }  
            set  
            {  
                if (this.subjectEN != value)  
                {  
                    this.subjectEN = value;  
                    this.OnPropertyChanged("SubjectEN");  
                }  
            }  
        }  
 
        private string locationEN = string.Empty;  
        public string LocationEN  
        {  
            get { return this.locationEN; }  
            set  
            {  
                if (this.locationEN != value)  
                {  
                    this.locationEN = value;  
                    this.OnPropertyChanged("LocationEN");  
                }  
            }  
        }  
 
        private string descriptionEN = string.Empty;  
        public string DescriptionEN  
        {  
            get { return this.descriptionEN; }  
            set  
            {  
                if (this.descriptionEN != value)  
                {  
                    this.descriptionEN = value;  
                    this.OnPropertyChanged("DescriptionEN");  
                }  
            }  
        }     
    }  
}  
 

I run the project, All appointments are coming to screen in Scheduler control. But I select an appointment, showing my custom edit dialog and getting all values. No problem. I want to add new appointment. I click empty line and openning CustomAppointmentEditDialog. I write some things. I click OK button. But I bought an exception. Is is following.

Exception Message :

Property accessor 'SubjectEN' on object 'Telerik.WinControls.UI.Appointment' threw the following exception:'Object does not match target type.' 

Stack Trace :

"   at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)\r\n   at Telerik.WinControls.UI.Scheduler.BindingProviderBase`1.UpdateDataItemProperty(Object item, T schedulerItem, SchedulerMapping mapping)\r\n   at Telerik.WinControls.UI.Scheduler.BindingProviderBase`1.UpdateDataItemProperties(Object item, T schedulerItem)\r\n   at Telerik.WinControls.UI.Scheduler.BindingProviderBase`1.InsertCore(T itemToInsert)\r\n   at Telerik.WinControls.UI.SchedulerBindingDataSource.EventBindingProvider.InsertCore(IEvent itemToInsert)\r\n   at Telerik.WinControls.UI.Scheduler.BindingProviderBase`1.Insert(T itemToInsert)\r\n   at Telerik.WinControls.UI.RadScheduler.OnAddAppointments(IList list)\r\n   at Telerik.WinControls.UI.RadScheduler.appointments_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)\r\n   at Telerik.WinControls.Data.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)\r\n   at Telerik.WinControls.Data.ObservableCollection`1.NotifyListenersCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n   at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)\r\n   at Telerik.WinControls.Data.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)\r\n   at Telerik.WinControls.Data.ObservableCollection`1.InsertItem(Int32 index, T item, Action`1 approvedAction)\r\n   at Telerik.WinControls.Data.ObservableCollection`1.InsertItem(Int32 index, T item)\r\n   at Telerik.WinControls.UI.SchedulerAppointmentCollection.InsertItem(Int32 index, IEvent item)\r\n   at System.Collections.ObjectModel.Collection`1.Add(T item)\r\n   at Telerik.WinControls.UI.RadScheduler.AddNewAppointmentWithDialog(DateTimeInterval interval, Boolean recurringAppointment, SchedulerResourceCollection resources)\r\n   at Telerik.WinControls.UI.DayViewAppointmentsTable.cell_DoubleClick(Object sender, EventArgs e)\r\n   at Telerik.WinControls.RadItem.OnDoubleClick(EventArgs e)\r\n   at Telerik.WinControls.RadItem.DoDoubleClick(EventArgs e)\r\n   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)\r\n   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)\r\n   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args)\r\n   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args)\r\n   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e)\r\n   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e)\r\n   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e)\r\n   at Telerik.WinControls.UI.RadScheduler.OnMouseUp(MouseEventArgs e)\r\n   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n   at System.Windows.Forms.Control.WndProc(Message& m)\r\n   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n   at Telerik.WinControls.RadControl.WndProc(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n   at System.Windows.Forms.Application.Run(ApplicationContext context)\r\n   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()\r\n   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()\r\n   at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)\r\n   at KocSchool_Grades.TestProject.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81\r\n   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.ThreadHelper.ThreadStart()" 

    This code ,
        NewAppointmentObject newAppObj = ev as NewAppointmentObject;  
    
    return null.. 
    
I think, it can not do casting. 
    NewAppObj return NULL after casting.. !!

        protected override void ApplySettingsToEvent(Telerik.WinControls.UI.IEvent ev)  
        {  
            NewAppointmentObject newAppObj = ev as NewAppointmentObject;  
 
            if (newAppObj != null)  
            {  
                newAppObj.SubjectEN = this.txtSubjectEN.Text;  
                newAppObj.LocationEN = this.txtLocationEN.Text;  
                newAppObj.DescriptionEN = this.txtDescriptionEN.Text;  
            }  
 
            base.ApplySettingsToEvent(ev);  
        } 

    I did it same things in help document. My WinForms controls version is 2009 Q3, but same code was running my previous version that is 2008 Q2.

from now, thanks for all helps..

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 25 Nov 2009, 03:20 PM
Hi MaviSeffaf,

Please find the answer to the question in your support ticket regarding the same topic.

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
KocSchool
Top achievements
Rank 2
answered on 01 Dec 2009, 08:02 AM
I posted same topic this here. :) Before when I opened support ticket.
My Problem is resolved.. I forgot to close this topic..

thanks for helps..
Tags
Scheduler and Reminder
Asked by
KocSchool
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
KocSchool
Top achievements
Rank 2
Share this question
or