Results 1 to 19 of 19

Thread: [RESOLVED] [2005] DateTimePicker Control question?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Resolved [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,
    Blake

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Last edited by jmcilhinney; Apr 23rd, 2008 at 09:10 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: [2005] DateTimePicker Control question?

    jmc,

    Your suggestion worked. Thanks!
    Blake

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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??

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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,
    Blake

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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.
    Blake

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: [RESOLVED] [2005] DateTimePicker Control question?

    Here ya go Kleinma...
    Blake

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] [2005] DateTimePicker Control question?

    ok I think I got it figured out.. gimme one min to finish testing.

  14. #14
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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,
    Blake

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  17. #17

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    Re: [RESOLVED] [2005] DateTimePicker Control question?

    Thanks,

    I appreciate your help Kleinma!!!
    Blake

  18. #18

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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,
    Blake

  19. #19

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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,
    Blake

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width