In .NET 1.1 I used to use the ExtendedDateTimePicker control from the Quantum Software Solutions Windows Forms Components library. Unlike some of their other components, the ExtendedDateTimePicker is not compatible with .NET 2.0, so I have created a control that works similarly, although not exactly the same way.
Control is blank (instead of showing greyed text) when ShowCheckBox is true and Checked is false.
DataValue property allows you to assign null values.
DataValueChanged event is raised only when the DataValue property value changes.
The main advantage of the DataValue property is that it allows you to bind the control to a database field and simply uncheck the control to assign a null value to the database. It accepts DateTime objects to set the date/time or a null reference or DBNull.Value to clear it. When cleared, the property always returns DBNull.Value. Note that if ShowCheckBox is false then assigning a null value to the DataValue property has no immediate effect, i.e. the control still displays text and the DataValue property still returns a DateTime object. If ShowCheckBox becomes true however, the change then becomes apparent, i.e. the control is blank and the DataValue property returns DBNull.Value. This means basically that if the control is intended to be able to contain a null value then ShowCheckBox must be true.
The ValueChanged event of the DateTimePicker is raised at times when the Value property value hasn't actually changed. In contrast, the DataValueChanged event of this NullableDateTimePicker is only raised when the DataValue property value has changed. This will occur if the ShowCheckBox is true and the DataValue property value changes from null to a date/time or a date/time to null, or else when the DataValue property value changes from one data/time value to another.
If you use this code and find any issues please post here.
This looks great - exactly what I need.
I'm a bit of a beginner with VB .NET 2008.
Ive copied your code into a class in my project but I'm not sure how to use the control in a form. I just drag an drop the datetimepicker from the datasource window. No doubt this is dead simple and I'm just being rather dim :-(
I'd actually suggest that you don't use this control. There's a bug in it that I didn't ever get around to fixing because QSS ended up releasing their WFC library for .NET 2.0. I'd suggest you follow that first link in the original post and get that.
Jm, any new solutions for the DTP? I'm having the same problem, I can null a date in the sql server with code and it saves fine, it's just the DTP control, when it runs over a null record it shows the value of the previous record, btw, the DTP works fine in a datarepeater for me with the checkbox but I want to get away from the datarepeater, thanks dotnet 3.5sp1