Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > DatePicker > Month Picker minimum date

Not answered Month Picker minimum date

Feed from this thread
  • Keith avatar

    Posted on Feb 8, 2012 (permalink)

    Hi

    I've got a custom RadDatePicker picker column within in RadGridView which is working great however we need to set a minimum date and a maximum date range. In my CreateCellEditElement, I create the DatePicker instance and set its properties. I've tried setting the SelectableStartDate and SelectableEndDate properties to our required values but these just seem to get ignored...

    RadDatePicker cellEditElement = new RadDatePicker()
                                            {
                                                DateSelectionMode = Telerik.Windows.Controls.Calendar.DateSelectionMode.Month,
                                                DisplayDateStart = dteStart, DisplayDateEnd = dteEnd,
                                                SelectableDateStart = dteStart, SelectableDateEnd = dteEnd
                                            };


    Please can you explain how I can set these properties?

    Thanks
    Keith

    Reply

  • Georgi Georgi admin's avatar

    Posted on Feb 9, 2012 (permalink)

    Hello Keith,

    In order to achieve flexibility in our controls we give the user the freedom to handle the behavior of setting date out of the range.

    For example you can handle it like this:
    public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                this.RadDateTimePicker.ParseDateTimeValue += RadDateTimePicker_ParseDateTimeValue;
            }
     
     
            private void RadDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
            {
                var dateTimePicker = sender as RadDateTimePicker;
     
                if (args.IsParsingSuccessful)
                {
                    if (args.Result < dateTimePicker.SelectableDateStart)
                    {
                        args.Result = dateTimePicker.SelectableDateStart;
                    }
                    if (args.Result > dateTimePicker.SelectableDateEnd)
                    {
                        args.Result = dateTimePicker.SelectableDateEnd;
                    }
                }
            }
        }

    Don't hesitate to contact us if you have other questions.



    Greetings,
    Georgi
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Keith avatar

    Posted on Feb 10, 2012 (permalink)

    Hi Georgi

    Thanks for the response but that event does not seem to get fired either when I type the new date in or select it. As I said it's implemented within a custom RadGridViewColumn and so I've registered that event in the CreateCellElement method. Is this the correct place?

    public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
    {
        var dteNow = DateTime.Today.AddDays(DateTime.Today.Day - 1);
        var dteStart = dteNow.AddMonths(-24);
        var dteEnd = dteNow.AddYears(30);
     
        RadDatePicker cellEditElement = new RadDatePicker()
                                                {
                                                    DateSelectionMode = Telerik.Windows.Controls.Calendar.DateSelectionMode.Month,
                                                    DisplayDateStart = dteStart, DisplayDateEnd = dteEnd,
                                                    SelectableDateStart = dteStart, SelectableDateEnd = dteEnd
                                                };
        cellEditElement.ParseDateTimeValue += (s, args) =>
        {
            var dateTimePicker = s as RadDateTimePicker;
     
            if (args.IsParsingSuccessful)
            {
                if (args.Result < dateTimePicker.SelectableDateStart)
                {
                    args.Result = dateTimePicker.SelectableDateStart;
                }
                if (args.Result > dateTimePicker.SelectableDateEnd)
                {
                    args.Result = dateTimePicker.SelectableDateEnd;
                }
            }
     
        };
     
        this.BindingTarget = RadDatePicker.SelectedDateProperty;
     
        cellEditElement.Culture = new System.Globalization.CultureInfo("en-GB");
        cellEditElement.Culture.DateTimeFormat.ShortDatePattern = "MM/yyyy";
        cellEditElement.DisplayFormat = DateTimePickerFormat.Short;
     
        Binding valueBinding = this.CreateValueBinding();
        cellEditElement.SetBinding(RadDatePicker.SelectedDateProperty, valueBinding);
     
        _originalValue = cellEditElement.SelectedDate;
     
        return cellEditElement as FrameworkElement;
    }


    Thanks
    Keith

    Reply

  • Georgi Georgi admin's avatar

    Posted on Feb 10, 2012 (permalink)

    Hi Keith,

    It works in my project. I am sending it as an attached file. Can you please check it out and tell me if it helped you?

    If you still have the problem it could be helpful to send us a support ticket with an attached sample project.

    Regards,
    Georgi
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > DatePicker > Month Picker minimum date
Related resources for "Month Picker minimum date"

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