[RESOLVED] [2005] DateTimePicker Control question?
I am using the DateTimePicker control on a form and was wondering if there is anyway of setting the textbox portion of it to spaces/null values. When I load my form, I wish for the space to be blank until a user selects a date. Is it possible to initialize it to a null value or spaces?
Thanks,
Re: [2005] DateTimePicker Control question?
The opposite problem we're having.
Yes you can. There should be a "Nullable"property on the DTP.... set it to true. Then in the load event, set it to Null.... When we did that, quite unintentionally, the DTP reported "(none)" as the "date".
-tg
Re: [2005] DateTimePicker Control question?
I think you're making that up tg. ;) You must be using a third-party/derived control because the standard DataTimePicker control supports no such functionality. What you can do is set the Format to Custom and the CustomFormat to " ", i.e. a string containing a single space. That will blank out the text of the control.
Alternatively you can set ShowCheckBox to True and allow the Checked property to indicate whether a value is present or not. When the control is unchecked the text is greyed by default.
There are various third-party date controls available that do provide this functionality. The WFC library from QSS includes an control derived from the standard DateTimePicker that uses the CustomFormat to blank the text as I mentioned above. It also provides additional functionality to allow binding to data that contains null values, which the standard DTP also doesn't support. Note that I've used the .NET 1.1 version of that control and it worked well. I also happen to know that the .NET 1.1 version definitely did not work under .NET 2.0. I assume that they have overcome that issue and included a new version since they updated the library to .NET 2.0, although I haven't used the new version so I don't know for sure.
Note also that .NET 2.0 libraries will work without issue under .NET 3.x. In fact, if you check the references in a .NET 3.5 app you'll see that most of the Framework assemblies are version 2.0 anyway.
Re: [2005] DateTimePicker Control question?
jmc,
Your suggestion worked. Thanks!
Re: [RESOLVED] [2005] DateTimePicker Control question?
FYI a true nullable date control was something people were griping for at the MVP summit. So perhaps we will see one eventually.
I wonder if the existing DTP can simply be extended to support a null value??
Re: [RESOLVED] [2005] DateTimePicker Control question?
Quote:
Originally Posted by kleinma
I wonder if the existing DTP can simply be extended to support a null value??
Yes it can. As I said, that's exactly what QSS have done in WFC.
Re: [RESOLVED] [2005] DateTimePicker Control question?
I think the biggest problem is the control drawing, as the control doesnt support custom drawing, so you have to use SetStyles in the derived class, which usually leads to many headaches with standard windows controls that are not meant to be custom drawn by default.
Re: [RESOLVED] [2005] DateTimePicker Control question?
Instead of starting another thread, I just wanted to know if there is a way, that once a date is selected from the drop-down calendar, you can force the calendar to go away. With my controls, sometimes it goes away right away when I select a date and other times I have to click on another control. I've tried setting focus to another control or the form and that doesn't work. Even tried doing a refresh of the control and that didn't work. Any ideas?
Thanks,
Re: [RESOLVED] [2005] DateTimePicker Control question?
by nature, when you click on a date from the drop down calendar, the calendar does go away.
Can you describe the scenario where this is not the case? I can't repro it.
Re: [RESOLVED] [2005] DateTimePicker Control question?
Well, it's pretty basic. I've got 4 DTP on a form. I've set the Format property to Custom and the CustomFormat property to a space. When I run the app and click on each DTP and select a date, it will populate the textbox but the Calendar won't disappear everytime. Sometimes it does and sometimes it doesn't. It's not consistent at all.
Re: [RESOLVED] [2005] DateTimePicker Control question?
If you can zip up a small example project that shows this, I can take a look at it for you, but even when I set the same properties you mention, I still can't get it to NOT go away after selecting a date from the drop down.
Re: [RESOLVED] [2005] DateTimePicker Control question?
Re: [RESOLVED] [2005] DateTimePicker Control question?
ok I think I got it figured out.. gimme one min to finish testing.
Re: [RESOLVED] [2005] DateTimePicker Control question?
Well I found the CAUSE of the problem. However I am not 100% sure if its by design or a bug, or how you would work around it.
If you change the format property in the ValueChanged event, it causes the drop down to NOT go away. I sort of think this is a bug, but I will check with some people at MS and see what they have to say.
The reason you see it go away sometimes, is when you select the already selected date, because behind the scenes, it doesn't fire off that event. Or when the format has already been changed to shortdate.
Also the code you have here:
dtRequestedDate.Value = CDate(dtRequestedDate.Value)
is redundant. You are assigning the same thing to the same thing.
Re: [RESOLVED] [2005] DateTimePicker Control question?
Quote:
Originally Posted by kleinma
Well I found the CAUSE of the problem. However I am not 100% sure if its by design or a bug, or how you would work around it.
If you change the format property in the ValueChanged event, it causes the drop down to NOT go away. I sort of think this is a bug, but I will check with some people at MS and see what they have to say.
The reason you see it go away sometimes, is when you select the already selected date, because behind the scenes, it doesn't fire off that event. Or when the format has already been changed to shortdate.
Also the code you have here:
dtRequestedDate.Value = CDate(dtRequestedDate.Value)
is redundant. You are assigning the same thing to the same thing.
That's cool.
However, the reason I change the Format property is because the way I have it set at design time, it give me an error message unless I reset it to the ShortDate from Custom. Is there a better event to set this Format property in?
Thanks,
Re: [RESOLVED] [2005] DateTimePicker Control question?
Yeah, I totally see why you are doing it, and in my personal opinion, it should not give you the problem it is giving you.
I am not really sure about a workaround just yet, but I did put an email into some people who may have a solution. I will let you know.
Re: [RESOLVED] [2005] DateTimePicker Control question?
Thanks,
I appreciate your help Kleinma!!!
Re: [RESOLVED] [2005] DateTimePicker Control question?
I did what JMC said to do in post #3 and for some reason in the ValueChanged Event when I select a date....no date appears in the Dropdown box. Do I need to reset the Format property?
Thanks,
Re: [RESOLVED] [2005] DateTimePicker Control question?
Ok, I got it to work part way. In the ValueChanged Event, after a date was selected...I changed the Format back to "Short". However, the calendar will not close unless I click on another control. It basically doesn't close automatically when a date value is selected. How can I fix that?
Thanks,