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

Default selected month/year when DateSelectionMode==Month

3 Answers 172 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 20 Aug 2010, 03:58 PM
I'm using the RadCalendar in Month selection mode (DateSelectionMode="Month"). I want the control to default to the current month and for this month to be visibly selected by default as well.

When I default the SelectedDate and/or DisplayDate properties to the current date the current month is still not visibly selected.

The only way I can get this to work is via a hack like:
Loaded += (s, e) =>
{
  var today = DateTime.Today;
  calendar.SelectedDate = new DateTime(today.Year, today.Month, 2);
  calendar.SelectedDate = new DateTime(today.Year, today.Month, 1);
};

Is this a bug? Is there a better way to default to the current month?

3 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 25 Aug 2010, 08:52 AM
Hello Chris,

This is the only possible way to select a date when onload is presented, as most of the control parts of the RadCalendar are properly loaded.  

Sincerely yours,
Kaloyan
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Chris
Top achievements
Rank 1
answered on 26 Aug 2010, 11:54 AM
Thanks for your response Kaloyan.

Perhaps I was not clear enough, but this is not an appropriate long-term solution given our usage of this control.

The only way to get a default selection to display in "Month" selection mode is to set the SelectedDate to the first day of a given month/year. However, this is not enough, as we also need to set it twice - once to some other day of the month/year (like 2), and then to 1 (as in the example code I provided).

This is not appropriate as we have bindings to the SelectedDate property which cause events to fire when the value is changed, resulting in long-running operations like database queries. So the required hack to change the SelectedDate twice to get a visual default selection is a big issue for us.

Surely the visual default selection of the calendar in "Month" mode should be the month/year of the current value of the SelectedDate? Also, it doesn't make sense that the SelectedDate must only be set to the 1st day of a month/year for a default to display.
0
Kaloyan
Telerik team
answered on 27 Aug 2010, 11:35 AM
Hello Chris,

There is no need to set the SelectedDate twice. Setting the property to the first day of the month will lead you to the desire result. Unfortunately this may be considered as a bug in our implementation of the control.  We will try to fix the issue for the next release.

All the best,
Kaloyan
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
Tags
Calendar
Asked by
Chris
Top achievements
Rank 1
Answers by
Kaloyan
Telerik team
Chris
Top achievements
Rank 1
Share this question
or