Month Picker minimum date

4 posts, 0 answers
  1. Keith
    Keith avatar
    88 posts
    Member since:
    May 2007

    Posted 08 Feb 2012 Link to this post

    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
  2. Georgi
    Admin
    Georgi avatar
    347 posts

    Posted 09 Feb 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Keith
    Keith avatar
    88 posts
    Member since:
    May 2007

    Posted 10 Feb 2012 Link to this post

    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
  5. Georgi
    Admin
    Georgi avatar
    347 posts

    Posted 10 Feb 2012 Link to this post

    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 >>
Back to Top