Calendar Converting ValueChangedEventArgs to DateTime

3 posts, 0 answers
  1. Raymond
    Raymond avatar
    19 posts
    Member since:
    Jun 2019

    Posted 01 Jul 2019 Link to this post

    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. Raymond
    Raymond avatar
    19 posts
    Member since:
    Jun 2019

    Posted 01 Jul 2019 in reply to Raymond Link to this post

    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.

  3. Yana
    Admin
    Yana avatar
    5044 posts

    Posted 02 Jul 2019 Link to this post

    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
Back to Top