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.
Printable View
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.
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.
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.
That's actually part of what the ExtendeddateTimePicker does but it goes further. The ability to bind null values is the big draw-card.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.Quote:
Originally Posted by RobDog888
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.
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.
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.Quote:
Originally Posted by jmcilhinney
my column currently allows null values since its not a critical data.