Setting SelectedDates

7 posts, 1 answers
  1. Toby
    Toby avatar
    59 posts
    Member since:
    Jul 2009

    Posted 03 Jun 2010 Link to this post

    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,

  2. Rick Glos
    Rick Glos avatar
    70 posts
    Member since:
    Mar 2009

    Posted 03 Jun 2010 Link to this post

    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>(); 


  3. UI for WPF is Visual Studio 2017 Ready
  4. Toby
    Toby avatar
    59 posts
    Member since:
    Jul 2009

    Posted 04 Jun 2010 Link to this post

    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.


  5. Rick Glos
    Rick Glos avatar
    70 posts
    Member since:
    Mar 2009

    Posted 04 Jun 2010 Link to this post

    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.
  6. Answer
    Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 08 Jun 2010 Link to this post

    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.
  7. Robert
    Robert avatar
    16 posts
    Member since:
    Dec 2010

    Posted 18 Jan 2011 Link to this post

    Hello Everybody,
    Any news about ItemsSource property in RadCalendar ?
  8. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 21 Jan 2011 Link to this post

    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>>
Back to Top
UI for WPF is Visual Studio 2017 Ready