Moving the calendar back and forward through dates |
Post Reply |
Author | |
WaaZ
Senior Member Joined: 31 January 2006 Location: United Kingdom Status: Offline Points: 103 |
Post Options
Thanks(0)
Posted: 01 November 2006 at 7:16am |
Using 9.81 ActiveX I keep getting the following error when the user press the forward or back button below is the error and below that is the code which produces the error. This problem does not show on my computer but only on some computers. Exception:
System.Exception: TargetInvocationException in Navigate_Cal_Back_And_Forward()., CalendarControl.ViewType = xtpCalendarDayView, CalendarControl.ActiveView.DaysCount = 1, date range = 2006-11-02 00:00:00.000 to 2006-11-02 00:00:00.000
Stack Trace:
JotmeApp.Calendar.CalendarBoardControl.Navigate_Cal_Back_And_Forward at JotmeApp.Calendar.CalendarBoardControl.Navigate_Cal_Back_And_Forward(Boolean forward) at JotmeApp.Calendar.CalendarBoardControl.Cal_Move_Forward_Click(Object sender, EventArgs e) at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Label.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) Now the code which produces the error:
{ DateTime DateBegin = DateTime.Today; DateTime DateEnd = DateTime.Today;AxXtremeCalendarControl. AxDatePicker datePicker = this.mainFromRef.DatePicker; if (datePicker.Selection.BlocksCount > 0){ DateBegin = datePicker.Selection[0].DateBegin;
DateEnd = datePicker.Selection[0].DateEnd; }
switch (CalendarControl.ViewType)
{ case CalendarViewType.xtpCalendarDayView: case CalendarViewType.xtpCalendarWorkWeekView: //************ DEBUG VERSION ****************************************** int daysCount = CalendarControl.ActiveView.DaysCount; DateTime rangeStart = DateBegin.AddDays(forward? daysCount : -daysCount ); DateTime rangeEnd = DateEnd.AddDays(forward? daysCount : -daysCount ); Application.DoEvents(); try{ if (!CalendarControl.IsDisposed){ CalendarControl.DayView.ShowDays(rangeStart, rangeEnd); } } catch (Exception ex){ throw new Exception(ex.GetType().Name + " in Navigate_Cal_Back_And_Forward()."+ ", CalendarControl.ViewType = " + CalendarControl.ViewType.ToString()+ ", CalendarControl.ActiveView.DaysCount = " + daysCount+ ", date range = " + rangeStart.ToString("yyyy-MM-dd HH:mm:ss.fff")+ " to " + rangeEnd.ToString("yyyy-MM-dd HH:mm:ss.fff")); } //************ DEBUG VERSION ****************************************** break; case CalendarViewType.xtpCalendarMonthView: if (forward){ CalendarControl.ViewChanged -= new System.EventHandler(this.CalendarControl_ViewChanged);CalendarControl.ActiveView.ShowDay(DateEnd.AddDays(5), true);CalendarControl.ViewChanged += new System.EventHandler(this.CalendarControl_ViewChanged);CalendarControl.ViewType = XtremeCalendarControl. CalendarViewType.xtpCalendarMonthView;} else{ CalendarControl.ViewChanged -= new System.EventHandler(this.CalendarControl_ViewChanged);CalendarControl.ActiveView.ShowDay(DateBegin.AddDays(-5), true);CalendarControl.ViewChanged += new System.EventHandler(this.CalendarControl_ViewChanged);CalendarControl.ViewType = XtremeCalendarControl. CalendarViewType.xtpCalendarMonthView;} break; case CalendarViewType.xtpCalendarWeekView: if (forward){ CalendarControl.ActiveView.ShowDay(DateEnd.AddDays(1), false);} else{ CalendarControl.ActiveView.ShowDay(DateBegin.AddDays(-1), false);} break;} } | |
WaaZ
Senior Member Joined: 31 January 2006 Location: United Kingdom Status: Offline Points: 103 |
Post Options
Thanks(0)
|
CodeJock people, I have a new patch comming out this weekend and I would really appreciate a reply.
Thanks
|
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
Hi,
I think I see the problem. It might happen because Dates are represented in OLE by Double values. And 2 equal Dates could be represented by not exactly same Doubles. The defference is small, but we have to keep in mind this when compare Dates. This is not implemented in ShowDays and as a result sometimes it removes all days and do not adds one. To avoid that use ShowDay method to show only one day. -- WBR, Serge |
|
sserge
Moderator Group Joined: 01 December 2004 Status: Offline Points: 1297 |
Post Options
Thanks(0)
|
Another possible easy solution would be to add some amount of time to rangeEnd (1 minute for example). In this case Doubles should be compared fine...
-- WBR, Serge |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |