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

Setting SelectedDates

6 Answers 277 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Toby
Top achievements
Rank 1
Toby asked on 03 Jun 2010, 04:46 PM
Hi,
Hopefully a quick question:
With the calendar control there is a SelectedDate property which allows me to get/set a date to be highlighted/selected. However i need to highlight/select a daterange from code. There is a selectedDates property, which allows you to get a List<DateTime> of selected dates, however i need to set this. Is there a way to do this?
Many thanks,

6 Answers, 1 is accepted

Sort by
0
Rick Glos
Top achievements
Rank 1
answered on 03 Jun 2010, 07:51 PM
I'm interested in the answer to this as well.  According to the documentation, this is bindable - see here.

Although it is exposed as a list, you can bind it and... 

But when attempting to use it you get an error.

'SelectedDates' property is read-only and cannot be set from markup.  

Or if you try and set in code you get an error.

            // Property or indexer 'Telerik.Windows.Controls.RadCalendar.SelectedDates' cannot be assigned to -- it is read only 
            radCalendar1.SelectedDates = new List<DateTime>(); 


0
Toby
Top achievements
Rank 1
answered on 04 Jun 2010, 12:04 PM
Your link to the documentation got me thinking. I tried the following as a work around:
private void setDate(DateTime from, DateTime to) 
        { 
            //clear selection 
            dateRangeCalendar.SelectedDate = null
            //loop through range 
            DateTime dateToAdd = from; 
            while (dateToAdd <= to) 
            { 
                //add to selection 
                dateRangeCalendar.SelectedDates.Add(dateToAdd); 
                dateToAdd = dateToAdd.AddDays(1); 
            } 
        } 

It would be helpful to be able to directly bind to a list, or set the list directly, however this should achieve the same thing.


0
Rick Glos
Top achievements
Rank 1
answered on 04 Jun 2010, 03:06 PM
Interesting, I didn't think to use the methods hanging off the IList.  This would certainly give us a work-around.  Although like you, I was hoping to bind this directly to my ViewModel.  It would involve a bit of code hanging off the event handlers on the control to keep this list updated in both directions.

Telerik, can you tell us was this an oversight, making this property ReadOnly or done purposely?  It would help us determine a course of action.
0
Accepted
Kaloyan
Telerik team
answered on 08 Jun 2010, 04:16 PM
Hello Rick Glos,

As you have noticed the property has a readonly accessor. You need to use the Add() method in order to add dates. We will consider adding an ItemsSource property that can be used with MVVM pattern.

Best wishes,
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
Robert
Top achievements
Rank 1
answered on 18 Jan 2011, 01:19 PM
Hello Everybody,
Any news about ItemsSource property in RadCalendar ?
0
Kaloyan
Telerik team
answered on 21 Jan 2011, 08:50 AM
Hello Toby,

There is no such a property exposed by the RadCalendar yet. You can create an attached property that will add a new selected date into the calendar itself and use it as a binding target. Let us know if you need any further explanation.

Kind regards,
Kaloyan
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Calendar
Asked by
Toby
Top achievements
Rank 1
Answers by
Rick Glos
Top achievements
Rank 1
Toby
Top achievements
Rank 1
Kaloyan
Telerik team
Robert
Top achievements
Rank 1
Share this question
or