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

Issues manually entering a date into DateTimePicker

10 Answers 1170 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Sean
Top achievements
Rank 1
Sean asked on 17 Nov 2008, 04:52 AM
Just trying out the Telerik Controls for Win Forms to see if it is worth switching to them from the ones I currently use. However I had a couple of problems when trying to manually enter dates on the DateTimePicker.  I found that if the date has been set to the null date by hitting the DEL key, then you tab off the control, then you cannot type in a date when you tab back to that control.  Also the DateTimePicker does not recognise partially entered years i.e. 1/1/08 for 01/01/2008.

Is there a way to get around these issues?
Thanks

10 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 20 Nov 2008, 04:01 PM
Hello Sean,

Thank you for writing.

I managed to reproduce the described behavior and I agree that this should be changed. Unfortunately, I cannot give you any suitable work-around currently. Please, excuse us for the inconvenience. I have updated your Telerik points for bringing our attention to this. We will try to fix it as soon as possible.
 
If you have other questions, do not hesitate to contact me again.

Sincerely yours,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Fabien
Top achievements
Rank 2
answered on 21 Nov 2008, 02:46 PM
Hi,

I found a solution for this little issue.

The problem is that you can't set to nullValue because in source code of RadDateTimePickerElement there is a "BypassUpdateOnLostFocus" set to true. (I think)
But anyway, you cannot set the minvalue yourself, because Text won't be refresh. And if you refresh the Text yourself (RadDateTimePicker.DateTimePickerElement.TextBoxElement.TextBoxItem.Text), you'll have bad reactions (because of mask and RadMaskTextBox hosted in)

My solution is to do this :

Add an event for each RadDateTimePicker (same event for all in your form)

private void RadDateTimePicker_Leave(object sender, EventArgs e)  
{  
 RadDateTimePicker element = (RadDateTimePicker)sender;  
 if (String.IsNullOrEmpty(element.DateTimePickerElement.TextBoxElement.TextBoxItem.Text))  
  element.Value = element.NullDate.AddSeconds(1);  


so, if control lost focus, you'll set to default value as well.

Best regards,

Fabien

 

 

0
Martin Vasilev
Telerik team
answered on 25 Nov 2008, 03:00 PM
Hello Fabien,

Thank you for sharing your code with us.

Unfortunately, it does not bring the exact behavior, because it sets a min value. It is not suitable if you need a null value in your RadDateTimePicker. Nevertheless, your code could surely be useful to other Telerik customers and I have updated your Telerik points for your inquiry. I have also added this issue in our bug tracking system and it will be addressed in a future release.

If you have other questions, do not hesitate to contact me again.

Regards,
Martin Vasilev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Bill
Top achievements
Rank 1
answered on 05 Mar 2009, 01:58 PM
Here's a workaround I use.  If you....
    1) Set the NullDate property to blank at design time
    2) Set the Value property blank at design time
...then the following code works for us.  In this scenario the DateTimePicker control always stays null unless someone keys something into it:

    public partial class Form1 : Form  
    {  
        DateTime SampleDate = new DateTime(1900, 1, 1, 0, 0, 0);  
        public Form1()  
        {  
            InitializeComponent();  
 
            dtDate.Enter += new EventHandler(dtDate_Enter);  
            dtDate.Leave += new EventHandler(dtDate_Leave);  
            dtDate.SetToNullValue();  
        }  
 
        void dtDate_Enter(object sender, EventArgs e)  
        {  
            if (dtDate.Value == dtDate.NullDate || dtDate.Value == null)  
            {  
                dtDate.Value = SampleDate;  
            }  
        }  
 
        void dtDate_Leave(object sender, EventArgs e)  
        {  
            if (dtDate.Value == SampleDate)  
            {  
                dtDate.Value = dtDate.NullDate;  
            }  
        }  
    } 

 

So if the user tabs into the control they can start typing immediately over a new sample date that is provided.  If they press tab again without typing anything the field will be set to blank again. You must use a sample date that is not valid because it gets erased when the user leaves the control. This seems a bit cheesy so if someone has a better workaround I'd be interested...

0
Martin Vasilev
Telerik team
answered on 07 Mar 2009, 09:05 AM
Hello Bill,

Thank you for sharing your code with us.

I am glad that you have found work-around of this issue. I am sure that there are other users, that will find your code as useful too. We have plans to fix the issue, but our schedule is very tough and I cannot give a time frame at the moment.

Do not hesitate to contact us again, if you have any other questions. 

Best wishes,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Daniel
Top achievements
Rank 1
answered on 08 Oct 2009, 09:09 AM
Hi,
my DateTimePicker may not have a null Value, but i need a manually free enter date lika MS Access Control.

I meen, the DateTimePicker gets the Focus and clear the Datestring, now i can enter my new Date like 1.1.2000

How can i release this?
0
Martin Vasilev
Telerik team
answered on 12 Oct 2009, 02:51 PM
Hi Daniel,

Thank you for your question.

RadDateTimePicker does not support this kind of editing. In your case, you can find RadMaskedEditBox as more suitable control. Write me back if you have other questions.

Greetings,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Darko
Top achievements
Rank 1
answered on 27 Oct 2009, 09:04 AM
Hi BIll,

thanks for sharing your code. It worked well for me.
However, I still have problems applying this to a DateTime RadGridView Column.
Any ideas from the Telerik team for a possible workaround for the described problem?
Basically, I would like to be able to manually enter a value in a ActiveEditor of the RadGridView.

Thanks for your help,
Darko Konrad
0
Martin Vasilev
Telerik team
answered on 30 Oct 2009, 11:08 AM
Hi Darko,

Thank you for writing. This approach cannot be used directly for GridViewDateTimeColumn, because the value of RadGridView editor depends on the cell value. Actually, if the cell value is null, RadGridDateTimeEditor has similar behavior. It shows the default date (today) and if the end user do not choose a date and leave the cell, than the null value for that cell remains.

Greetings,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ruth Goldberg
Top achievements
Rank 1
answered on 03 May 2010, 02:57 PM
I found Bill's workaround very useful. But I also wanted the calendar to show today's date, so I set my NullDate to Now on form load and my SampleDate to 1 second later. This way, the user can also choose today's date from the calendar because the time will be different from the NullDate.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Sean
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Fabien
Top achievements
Rank 2
Bill
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Darko
Top achievements
Rank 1
Ruth Goldberg
Top achievements
Rank 1
Share this question
or