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

Calendar Converting ValueChangedEventArgs to DateTime

2 Answers 13 Views
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 01 Jul 2019, 11:50 PM

In the documentation for the calendar "SelectionChanged" event it states;

A ValueChangedEventArgs<object> object which provides old and new value of the SelectedDate. The values are of type object, but can be cast to the DateTime type.

The values are actually doubles and when the control is first bound (prior to the SelectionDate being set) my "SelectionChanged" handler is called with the following values;

args.NewValue:  1.66076571237391E-314

args.OldValue: -3.49537279385073E+40

If I attempt to convert either of the values using "Convert.ToDateTime(args.<value>)" I get the exception "Invalid cast from 'Double' to 'DateTime'".

If I attempt to convert the old value using "DateTime.FromOADate(args.args.OldValue)" I get the exception "Not a legal OleAut date".

And if I attempt to convert the old value using "TimeSpan.FromSeconds(args.OldValue)" I get the exception "TimeSpan overflowed because the duration is too long".

Can you clarify;

1) Exactly what "date" values are being passed in the ValueChangedEventArgs, and

2) What is the correct way to convert these to DateTime values.

2 Answers, 1 is accepted

Sort by
0
Raymond
Top achievements
Rank 1
answered on 02 Jul 2019, 01:58 AM

Found the solution to this problem here.  I had to change the signature from;

private void OnDateSelected(object sender, ValueChangedEventArgs args)

 

to;

private void OnDateSelected(object sender, ValueChangedEventArgs<object> args)

 

The new and old values (NewValue and PreviousValue) now contain the correct values.

0
Yana
Telerik team
answered on 02 Jul 2019, 06:17 AM
Hello Raymond,

Glad to hear you've managed to resolve the case.

Let me know if any additional questions regarding RadCalendar arise.

Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Raymond
Top achievements
Rank 1
Answers by
Raymond
Top achievements
Rank 1
Yana
Telerik team
Share this question
or