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

RadDateTimePicker Bad Behaviour

1 Answer 122 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Judy
Top achievements
Rank 1
Judy asked on 01 Oct 2008, 10:40 AM
I've got a RadDateTimePicker bound to a BindingSource (tied to an object datasource).  The minimum value property is set to 1/1/1970.    First of all, when I attempt to add a new employee record (the date is a Hire Date) and the date is empty, the control will not accept keystrokes.  I'm forced to drop the calendar down, select a date and then I can change it by keying in a date.  I'd like my users to be able to just key in a date right away rather than having to drop the calendar down first.

Second, if I select 1/1/1970 and then change it to 5/1/2008 and tab out of the field, the value returns to 1/1/1970!!  What's up with that?

I need to install a beta version of this app at a client this Friday and need an answer quick.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 02 Oct 2008, 04:11 PM
Hi Judy,

Indeed, when RadDateTimePicker Value is set to NullDate, you cannot type in the editing textbox portion. However, it is not necessary to open the calendar drop down to start typing again. Instead, when Entering the RadDateTimePicker, you can set a date different from the NullDate. This will display a date in the text box portion and you will be able to edit it.

As to your second question, the value of RadDateTimePicker is updated automatically when you stop writing in it. So, if you set a correct date and Leave the RadDateTimePicker after that, this date should stay. However, if you edit the year and type something like "200" and wait for about 500 miliseconds (0.5 second), the value will be updated the the MinDate value, because "200" is out of the date range, specified by MinDate and MaxDate properties.

In order to set a bigger time interval in which to set the correct date, please consider using the following workaround:
  1. Put the following code snippet in the Form() contructor after the InitializeComponent() method:
    Type t = this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.TextBoxItem.HostedControl.GetType();FieldInfo info = t.GetField("editingTimer", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);     
    Timer timer = new Timer();     
    timer.Interval = 2000;     
    info.SetValue(this.radDateTimePicker1.DateTimePickerElement.TextBoxElement.TextBoxItem.HostedControl, timer);     
    timer.Tick += new EventHandler(timer_Tick);      
     
  2. Now let me explain what happens. I get the Timer instance, which updates the Date on its Tick method call. Then I change this instance with a new instance and set its interval to 2000 miliseconds which is equal to 2 seconds. Lastly I subscribe to the Tick event of the new Timer instance where I do the following: 
    void timer_Tick(object sender, EventArgs e)     
    {     
        Type t = this.radDateTimePicker2.DateTimePickerElement.TextBoxElement.TextBoxItem.HostedControl.GetType();     
        MethodInfo info = t.GetMethod("editingTimer_Tick", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);     
        try    
        {     
            info.Invoke(this.radDateTimePicker2.DateTimePickerElement.TextBoxElement.TextBoxItem.HostedControl,     
            new object[] { sender, e });     
        }     
        catch (Exception ex)     
        {     
            // Show the exception message     
            // MessageBox.Show(ex.ToString());     
        }     
    }    
     
    Here I call our old timer's tick event handler as it won't be called for the new timer - this keeps the internal logic alive, but we have a new timer object which we use now.
I have demonstrated the approaches in the sample project attached.

If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Judy
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or