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

Crash on Adding a Custom Appointment

0 Answers 113 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Sébastien
Top achievements
Rank 1
Sébastien asked on 10 Jun 2011, 06:49 PM
Hi,

I get two crashes when adding a new appointment in a RadScheduleView.
The type of the appointments is a custom BFAppointment class that I made which inherits from AppointmentBase.
The type of the AppointmentsSource of the control is a BFAppointmentList class I made, and this one inherits from ObservableCollection<BFAppointment>, so this shouldn't be an INotifyCollectionChanged bug.

The two crashes are:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
   at System.Collections.ArrayList.get_Item(Int32 index)
   at System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
   at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
   at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.RemoveItem(Int32 index)
   at System.Collections.ObjectModel.Collection`1.RemoveAt(Int32 index)
   at System.Windows.Data.ListCollectionView.CancelNew()
   at Telerik.Windows.Controls.ScheduleView.ScheduleViewDataConnection.HackCollectionViewBug(Boolean isCommit) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleViewDataConnection.cs:line 875
   at Telerik.Windows.Controls.ScheduleViewBase.CommitNew(IAppointment appointment) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Editing.cs:line 341
   at Telerik.Windows.Controls.ScheduleViewBase.Commit() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Editing.cs:line 253
   at Telerik.Windows.Controls.ScheduleViewBase.OpenAppointmentDialog(Occurrence occurrence, AppointmentViewMode viewMode) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.EditingWithDialogs.cs:line 297
   at Telerik.Windows.Controls.ScheduleViewBase.CreateAppointmentWithDialog(Object parameter) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.EditingWithDialogs.cs:line 82
   at Telerik.Windows.Controls.ScheduleViewBase.OnCreateAppointmentExecuted(Object sender, ExecutedRoutedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Commands.cs:line 166
   at System.Windows.Input.CommandBinding.OnExecuted(Object sender, ExecutedRoutedEventArgs e)
...


and:

System.ArgumentOutOfRangeException: The added or subtracted value results in an un-representable DateTime.
Parameter name: value
   at System.DateTime.AddTicks(Int64 value)
   at System.DateTime.Add(Double value, Int32 scale)
   at Telerik.Windows.Controls.DateTimeExtensions.SubtractInterval(DateTime dt, DateTimeInterval dateTimeInterval) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Extensions\DateTimeExtensions.cs:line 17
   at Telerik.Windows.Controls.ScheduleViewBase.GetFirstPartOfOccurrencesWithNoEndDates(DateSpan range, IEnumerable`1 source, Boolean moveForward, DateTimeInterval interval) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Common.cs:line 3571
   at Telerik.Windows.Controls.ScheduleViewBase.HasAppointmentsInRange(DateSpan range, Boolean skipIntersectedWithTheRangeAppointments, Boolean moveForward, DateTimeInterval interval) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Common.cs:line 1316
   at Telerik.Windows.Controls.ScheduleViewBase.OnQueryGoToPreviousAppointmentCanExecuted(Object sender, CanExecuteRoutedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\ScheduleView\ScheduleView\Controls\ScheduleView.Commands.cs:line 300
   at System.Windows.Input.CommandBinding.OnCanExecute(Object sender, CanExecuteRoutedEventArgs e)

...

I have some custom code when creating an appointment, as shown here:

void m_scheduleView_AppointmentCreating( object sender, AppointmentCreatingEventArgs e )
        {
            BFAppointment appointment = e.Appointment as BFAppointment;
            appointment.Schedule = ViewModel.BaseEntity;

            ScheduleTimespan timespan = new ScheduleTimespan();
            timespan.ScheduleId = ViewModel.BaseEntity.Id;

            appointment.TimespanViewModel = new ScheduleTimespanViewModel( timespan, ServiceLocator.Get<IEntityManager>() );
        }

        /// <summary>
        /// Handles the display of default Telerik dialogs to cancel them and substitute mine.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RadScheduleView_ShowDialog(object sender, ShowDialogEventArgs e)
        {
            // Dialog used to ask if we want to edit only the current occurrence or the whole series.
            // Since we ONLY support series, we skip the dialog.
            if ( e.DialogViewModel is RecurrenceChoiceDialogViewModel )
            {
                RecurrenceChoiceDialogViewModel vm = e.DialogViewModel as RecurrenceChoiceDialogViewModel;

                vm.IsSeriesModeSelected = true;
                e.DefaultDialogResult = true;
                e.Cancel = true;
            }
            // Replace the Telerik occurrence editor with our own.
            else if ( e.DialogViewModel is AppointmentDialogViewModel )
            {
                AppointmentDialogViewModel vm = e.DialogViewModel as AppointmentDialogViewModel;
                BFAppointment appointment = ( vm.Occurrence.Appointment as BFAppointment );

                if ( appointment.TimespanViewModel != null )
                {
                    // Show a window to edit the appointment.
                    ScheduleTimespanViewModel timespanVM = appointment.TimespanViewModel;

                    ScheduleTimespanControl control = new ScheduleTimespanControl() { ViewModel = timespanVM };
                    GenericEditableWindow window = new GenericEditableWindow( control, "ScheduleProperties", ServiceLocator.Get<IMainWindow>() as Window, GenericEditableWindowModeEnum.OK );
                    window.ShowDialog();
                }

                e.DefaultDialogResult = true;
                e.Cancel = true;
            }
        }

Setting e.Handled = true; in the AppointmentCreating event doesn't fix the issue.
Any pointers would be greatly appreciated.

Sebastien

No answers yet. Maybe you can help?

Tags
ScheduleView
Asked by
Sébastien
Top achievements
Rank 1
Share this question
or