Results 1 to 10 of 10

Thread: datetimepicker control question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    datetimepicker control question

    is it possible to set a null value to this control?

    when inserting new records, i would like it to be null/empty initially and wait for user input.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: datetimepicker control question

    Set the CustomFormat property to a single space character. Then set the datetimepickers Format property to Custom. This will blank out the data with a space char as its value. When you are ready to load or display dates just change the CustomFormat back and set the Format property to what you desire.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: datetimepicker control question

    The DateTimePicker control does not inherently support null values. It's Value property is type Date, which is a value type, so it must always have a value. What you can do is set the ShowCheckBox property to True and have the check box indicate whether a value has been set or not. It's is a bit fiddly in some situations though and, unfortunately, it doesn't support data-binding. If you have a date column that can contain nulls then you cannot bind it to a DTP.

    Now, an alternative is to use the ExtendedDateTimePicker control in the library in my signature. I've used the .NET 1.1 version and it works well, including data-binding support. I haven't tried the .NET 2.0 version but I know that they had to make some changes because the same code was broken in .NET 2.0. The link only provides a download for the 2.0 version but if you e-mail them I'd think they'd make it available to you. If not then PM me your e-mail address and I can send it to you.
    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
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: datetimepicker control question

    Quote Originally Posted by RobDog888
    Set the CustomFormat property to a single space character. Then set the datetimepickers Format property to Custom. This will blank out the data with a space char as its value. When you are ready to load or display dates just change the CustomFormat back and set the Format property to what you desire.
    That's actually part of what the ExtendeddateTimePicker does but it goes further. The ability to bind null values is the big draw-card.
    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

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: datetimepicker control question

    But if you use the checkbox properties it still shows a date but "greyed out". My workaround will display "nothing" as to not confuse the user.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: datetimepicker control question

    Quote Originally Posted by RobDog888
    But if you use the checkbox properties it still shows a date but "greyed out". My workaround will display "nothing" as to not confuse the user.
    Like I said, that's what the ExtendedDateTimePicker does: when you uncheck the box it sets the CustomFormat to a space.
    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

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: datetimepicker control question

    thanks... unfortunately my column with date datatype is nullable... that might cause a problem even if i set the format to a single space. i'll probably need to set the column on my database to not allow a null value or to use the extended datetime picker.

    thanks for the info.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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

    Re: datetimepicker control question

    What does your column represent? Does it logically support null values or not? If not then you certainly should set its properties to not allow nulls, otherwise it should. That decision is not, or should not be, a matter of convenience. It should be a matter of logic. If it logically does support nulls and you want to use data-binding then the ExDTP will do the job.
    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

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: datetimepicker control question

    Quote Originally Posted by jmcilhinney
    That's actually part of what the ExtendeddateTimePicker does but it goes further. The ability to bind null values is the big draw-card.
    Yes, thats a nice feature but I prefer not having to rely upon third party controls (unless for non-commercial use) unless it comes with source code so I dont have to rely upon some other company to make bug fixes or compatibility for new framework versions or operating systems.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: datetimepicker control question

    my column currently allows null values since its not a critical data.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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