Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > DatePicker > How to disable selection for several dates

Answered How to disable selection for several dates

Feed from this thread
  • hadass avatar

    Posted on Jan 3, 2012 (permalink)

    Hi.
    I'm using telerikInput:RadDatePicker to select a date but i need to limit the selection.
    I have a list of unavailable dates (got pulled from the data base) that i don't want to allow the user to select. I want that when opening the DatePicker those dates will be disabled for selection.

    what is the best way to do it?

    Thanks, Hadass.

    Reply

  • Yana Yana admin's avatar

    Posted on Jan 4, 2012 (permalink)

    Hello Hadass,

    You should create a custom DayTemplateSelector and set it to the CalendarStyle of the DatePicker. I've attached a simple project to demonstrate the approach, please download it and examine it.

    Regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • hadass avatar

    Posted on Jan 5, 2012 (permalink)

    Hey Yana.
    Thanks for your reply.

    The code example you gave me is with Silverlight 4 and I'm using Silverlight 3.
    is it doable in Silverlight 3 ?

    (hence the "telerikInput" namespace : 

    xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"

    By the way, this is the namespace that i get when dragging the "RadDatePicker" control.)

    In your example:
       <telerik:RadDatePicker>
                <telerik:RadDatePicker.CalendarStyle>
                    <Style TargetType="telerik:RadCalendar">
                        <Setter Property="DayTemplateSelector" Value="{StaticResource CustomTemplateSelector}" />
                    </Style>
                </telerik:RadDatePicker.CalendarStyle>
    </telerik:RadDatePicker>

    the property

    <telerik:RadDatePicker.CalendarStyle>
     is just not available when using the telerikInput namespace.

    Thanks for your reply.
    Hadass.

    Reply

  • Yana Yana admin's avatar

    Posted on Jan 5, 2012 (permalink)

    Hi Hadass,

    Could you please tell us the exact version of the controls that you're using?

    Greetings,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • hadass avatar

    Posted on Jan 6, 2012 (permalink)

    Hi Yana

    I checked the details in the properties of the Telerik.Windows.Controls.dll
    The version is  2010.1.603.1030
    The runtime version is  v2.0.50727

    Is this the information you need?

    Thanks, Hadass

    Reply

  • Answer Yana Yana admin's avatar

    Posted on Jan 10, 2012 (permalink)

    Hello Hadass,

    It seems that you're using too old version of the controls and the approach for disabling days is different. I've attached a new SL3 project  to demonstrate it, please download the attachment and try it.

    Kind regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Attached files

    Reply

  • hadass avatar

    Posted on Feb 2, 2012 (permalink)

    Thanks for the solution. It helped a lot and solved my problem.

    Hadass.

    Reply

  • hadass avatar

    Posted on Feb 7, 2012 (permalink)

    Hi.
    After using this solution I bump into another problem.
    I have a list of invalid dates that I send to the costume selector, but this list updates dynamically. The problem is that the costume template selector doesn't refresh itself.

    I looked up for solutions online but I couldn't find anything related to DatePicker, though I found a thread from Telerik's forums about Calendar control, that has the same problem.

    http://www.telerik.com/community/forums/silverlight/calendar/redraw-refresh-radcalendar.aspx 

    Is this the same bug that was on old versions of Calendar control?
    if i'm using the Telerik and Silverlight versions that are mentioned above, is it possible to refresh the the costume day template?

    I add here the template I use:
    public class CustomTemplateSelector : DataTemplateSelector
        {
            private static List<DateTime> _invalidDays = new List<DateTime>();
     
            public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                CalendarButtonContent content = item as CalendarButtonContent;
                if (content != null)
                {
                    foreach (DateTime day in _invalidDays)
                    {
                        if (content.Date.Date == day | content.Date.Date < DateTime.Today)
                        {
                            content.IsEnabled = false;
                            return this.DisabledTemplate;
                        }
                    }
     
                }
                return this.DefaultTemplate;
            }
     
            public static void SetInvalidDays(List<DateTime> invalidDays)
            {
                _invalidDays = invalidDays;
            }
     
            public DataTemplate DisabledTemplate
            {
                get;
                set;
            }
     
            public DataTemplate DefaultTemplate
            {
                get;
                set;
            }
     
     
            public CalendarButtonContent List { get; set; }
        }


    and this is the call for it from the main page with the updated list of invalid dates:
    private void ActivateDatePickerTemplate()
    {
        List<DateTime> daysToDisable = new List<DateTime>();
        for (int i = 0; i < escortDates.Count; i++)
        {
            if (escortDates.ElementAt(i).Value >= limitPerDay)
            {
                daysToDisable.Add(escortDates.ElementAt(i).Key.Value);
            }
        }
        CustomTemplateSelector.SetInvalidDays(daysToDisable);
    }

    Thanks for your help.

    Reply

  • Answer Yana Yana admin's avatar

    Posted on Feb 16, 2012 (permalink)

    Hello Hadass,

    I am sorry for the delayed reply.

    You just need to change _invalidDays collection in the CustomTemplateSelector to be of type ObservableCollection<DateTime> as it implements INotifyCollectionChanged interface.

    I've attached the modified project, please download it and give it a try.

    Kind regards,
    Yana
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

  • hadass avatar

    Posted on Feb 26, 2012 (permalink)

    Hi.
    i didn't try your solution - we managed to by-pass the probelm by changing the DateTimePicker - SelectableDateEnd to a value and back to null..

    dtFromDate.SelectableDateEnd = DateTime.Today;
    dtFromDate.SelectableDateEnd = null;

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > DatePicker > How to disable selection for several dates
Related resources for "How to disable selection for several dates"

Silverlight DatePicker Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]