|
-
Jul 29th, 2007, 03:44 AM
#1
Thread Starter
Hyperactive Member
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
-
Jul 29th, 2007, 03:50 AM
#2
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jul 29th, 2007, 03:57 AM
#3
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.
-
Jul 29th, 2007, 04:01 AM
#4
Re: datetimepicker control question
 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.
-
Jul 29th, 2007, 04:01 AM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jul 29th, 2007, 04:07 AM
#6
Re: datetimepicker control question
 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.
-
Jul 29th, 2007, 04:11 AM
#7
Thread Starter
Hyperactive Member
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
-
Jul 29th, 2007, 04:16 AM
#8
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.
-
Jul 29th, 2007, 04:52 AM
#9
Re: datetimepicker control question
 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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jul 29th, 2007, 08:14 AM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|