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

Month Picker minimum date

3 Answers 94 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Keith
Top achievements
Rank 1
Keith asked on 08 Feb 2012, 10:49 AM
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

3 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 09 Feb 2012, 04:28 PM
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 >>
0
Keith
Top achievements
Rank 1
answered on 10 Feb 2012, 09:04 AM
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
0
Georgi
Telerik team
answered on 10 Feb 2012, 05:27 PM
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 >>
Tags
DatePicker
Asked by
Keith
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Keith
Top achievements
Rank 1
Share this question
or