Getting selected date in the RadCalendar SelectionChanging event

8 posts, 0 answers
  1. Peter
    Peter avatar
    14 posts
    Member since:
    Apr 2009

    Posted 18 Feb 2011 Link to this post

    I have a calendar set so that I highlight holiday dates etc on the calendar using the ElementRender event.

    I therefore need to use the SelectionChanging event to to all the pre-work required to get holidays etc from my database.

    My problem is that for some reason the SelectionEventArgs in tthe SelectionChanging event only tells me the currently selected date.

    How do I find the date that the users has just selected that fired the SelectionChanging event?

    For example the current date is 19 Feb 2011, the user selects 30 Mar 2011, SelectionEventArgs contains 19 Feb 2011, I need 30 Mar 2011.

    Thanks

  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Feb 2011 Link to this post

    Hello Peter,

    If I understand you correctly, you want to be able to highlight the holidays and other set dates that you have stored on the caledar. In order to highlight these days automatically, you can just use the SpecialDays (collection of calendar days) to highlight your days.

    this.radCalendar1.SpecialDays.Add(new RadCalendarDay(DateTime.Today.AddDays(6)));

    I hope this helps, but if I have mis-understood, then please let me know and I'll do my best to help.
    Regards,
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Peter
    Peter avatar
    14 posts
    Member since:
    Apr 2009

    Posted 19 Feb 2011 Link to this post

    Richard

    Thanks for the reply, I originally used SpecialDays but because of the complexity of the highlighting it was much quicker and simpler to use the ElementRender event (I display 6 months worth of calendar and potentially hundreds of days of highlighting and multiple highlights per day)

    The issue is not how to render the days but why the SelectionChanging changing event does not return the date that has caused the event to fire, rather it returns the date that is already selected. This would seem to make the event completely useless as there is no mechanism for determining whether the date about to be selected is valid or useful which is the main reason for a SelectionChanging event.

    I just happen to be using it to select from the database information based on the upcoming selection but it could be just as likely that I might want to stop a user from selecting that date based on other logic and cancel the changing event. This would seem to me to be an error in the design of the SelectionChanging event.

    I have got around the problem in what I consider a not very elegant but workable way, by determining the cell that was clicked and getting the date from that, see below

    DateTime selDate = this.RadCalendar1.FocusedDate;
    Point mouseLoc = this.RadCalendar1.PointToClient(Cursor.Position);
    Telerik.WinControls.RadElement selElement = this.RadCalendar1.ElementTree.GetElementAtPoint(mouseLoc);
    if (selElement != null && (CalendarCellElement)selElement is CalendarCellElement)
    {
        CalendarCellElement selCell = (CalendarCellElement)selElement;
        selDate = selCell.Date;
    }

    This is now working OK.

    Thanks

    Peter
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 19 Feb 2011 Link to this post

    Hi Peter,

    I agree that the RadCalendar should give you the date that you are switching to, and ideally an old and new date. In my view you have chosen the correct way to workaround this. Glad you have a solution
    Regards,
    Richard
  6. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 23 Feb 2011 Link to this post

    Hello guys,

    Thank you both for writing.

    I just wanted to mention that Peter's suggestion seems quite reasonable and I will add this into our PITS system as a feature request, which we will address in a future release. At this link you can subscribe for the status updates regarding this request.

    @Peter, your Telerik points are updated for the request.

    Thank you for this discussion.  

    All the best,
    Stefan
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  7. Peter Szintai
    Peter Szintai avatar
    28 posts
    Member since:
    Jul 2009

    Posted 23 Feb 2011 Link to this post

    Hi All,

    because I have also problems/issues with the RadCalender in the SelectionChanging event, I did not open a new thread.

    Some of the calendar settings: allowed multiple select and multi view, the RangeMinDate is 1900.01.02 (to check that this is not equal to 1900.01.01 later), the FocusedDate and SelectedDate are 2010.10.01 (the actual month of our test system).

    1. When I click first time to the 2010.10.02 cell, the e.Dates contains 5 elements (two times the today, three times the original RangeMinDate)
    +       [0]   {2011.02.23. 0:00:00}   System.DateTime
    +       [1]   {2011.02.23. 0:00:00}   System.DateTime
    +       [2]   {1900.01.01. 0:00:00}   System.DateTime
    +       [3]   {1900.01.01. 0:00:00}   System.DateTime
    +       [4]   {1900.01.01. 0:00:00}   System.DateTime

    after the second click it contains 6 elements (the last item is the date of the clicked cell)
    +       [0]   {2011.02.23. 0:00:00}   System.DateTime
    +       [1]   {2011.02.23. 0:00:00}   System.DateTime
    +       [2]   {1900.01.01. 0:00:00}   System.DateTime
    +       [3]   {1900.01.01. 0:00:00}   System.DateTime
    +       [4]   {1900.01.01. 0:00:00}   System.DateTime
    +       [5]   {2010.10.02. 0:00:00}   System.DateTime

    After the click on the Clear button it clears the e.Dates, and the e.Dates contains the perfect dates: 1 element or empty after the new clicks.

    2. If I turn off the multiple select, I see the behaviors of the first post:
    Clicks on the 2010.10.02 cell:
    1st click: e.Dates = today
    2nd click: e.Dates = 2010.10.02
    3rd click: e.Dates is empty
    and the e.Dates contains the perfect values of the next clicks, 1 element or empty.


    Best regards,

    Peter Szintai
  8. Peter
    Peter avatar
    14 posts
    Member since:
    Apr 2009

    Posted 23 Feb 2011 Link to this post

    Hi Peter

    I had exactly the same problem, the selected date is empty on the 3rd click, I am not using multiple select, so I got around it by checking the FocusedDate property if the e.Dates array was empty, note the SelectedDate property is also incorrect at this point.

    The FocusedDate always seems to be correct.

    I have been using the Ajax Telerik controls for many years but this is my first experience with the Winforms controls and in terms of functionality and documentation they definitely feel like the poor cousin of the Ajax controls.

    Peter
  9. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 28 Feb 2011 Link to this post

    Hi guys,

    Thank you both for writing.

    This issue is resolved in our development version and the fix will be released in our upcoming official release Q1 2011.

    @Peter Szintai, your Telerik points have been updated for the report.

    Kind regards,
    Dobry Zranchev
    the Telerik team

    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Back to Top
UI for WinForms is Visual Studio 2017 Ready