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

Getting selected date in the RadCalendar SelectionChanging event

9 Answers 309 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 19 Feb 2011, 04:57 AM
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

9 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 19 Feb 2011, 12:37 PM
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
0
Peter
Top achievements
Rank 1
answered on 19 Feb 2011, 11:42 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 20 Feb 2011, 12:32 AM
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
0
Stefan
Telerik team
answered on 23 Feb 2011, 08:35 AM
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!
0
Peter Szintai
Top achievements
Rank 1
answered on 23 Feb 2011, 02:26 PM
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
0
Peter
Top achievements
Rank 1
answered on 23 Feb 2011, 09:57 PM
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
0
Dobry Zranchev
Telerik team
answered on 28 Feb 2011, 04:29 PM
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!
0
Pradeep
Top achievements
Rank 1
answered on 28 Jun 2018, 11:38 AM

Hi,

How to get  a selected date from RadCalendar control in javascript and how to show/hide the radcontrol on button click at client side.

can anyone give me the solution.

Thanks,

Pradeep

0
Hristo
Telerik team
answered on 29 Jun 2018, 10:40 AM
Hi Pradeep,

This thread uses discusses the RadCalendar control for WinForms. Based on your question I assume that you might be using our controls for ASP.NET AJAX. If this is really the case please post your question in the proper forum.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Peter
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Peter
Top achievements
Rank 1
Stefan
Telerik team
Peter Szintai
Top achievements
Rank 1
Dobry Zranchev
Telerik team
Pradeep
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or