Posts Tagged ‘DateTimePicker’

Windows Forms DateTimePicker ShowCheckBox and not Checked bug in .NET 2.0

Monday, March 9th, 2009

I recently upgraded a project that I had inherited from another programmer to .NET 2.0. Shortly after, I received an email complaining that a date field had stopped saving correctly. I tried it out, and all looked fine in the user interface, but sure enough, the value was not being written to the database.

It took me some time to work out what was going on. The ShowCheckBox property was set to False, but the Checked property also was. For some reason, the DateTimePicker in .NET 2.0 interprets this as meaning that the value that is in the control is to be ignored, and it returns today’s date if you access the Value property.

This was a pretty simple fix – all it took was to set Checked to True, and it all worked fine again. It is an interesting gotcha to look out for though – I haven’t seen it documented anywhere as a breaking change of .NET 2.0