PDA

Click to See Complete Forum and Search --> : NullableDateTimePicker for .NET 2.0


jmcilhinney
Jul 22nd, 2006, 07:58 PM
In .NET 1.1 I used to use the ExtendedDateTimePicker control from the Quantum Software Solutions Windows Forms Components (http://www.quantumsoftware.com.au/ProductsServices/WindowsFormsComponents.aspx) 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.

Features:
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.


DataValue property:
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.

DataValueChanged event:
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.

JonnyPoet
Jul 7th, 2008, 03:29 PM
Thx for posting that. I'll do a try with it, as I hate the standard DateTimePicker

jmcilhinney
Jul 7th, 2008, 06:27 PM
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. To be honest I've not used their new version so I am only assuming that it contains an updated version of their DTP control.

JonnyPoet
Jul 7th, 2008, 06:42 PM
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. To be honest I've not used their new version so I am only assuming that it contains an updated version of their DTP control.What sort of bug is it ? as I couldn't find any problems with it in the moment ?

jmcilhinney
Jul 7th, 2008, 06:49 PM
What sort of bug is it ? as I couldn't find any problems with it in the moment ?To be honest I can't remember. It was quite a while ago now. I just recall that I tested it and it seemed to be working, so I posted it here. I then used it in a particular way and it didn't work properly. I do recall that it was a combination of actions that was unlikely to occur but even unlikely things occur sometimes.