views:

3626

answers:

4

What's the easiest/most robust way of altering the DateTimePicker control to allow the user to enter 'null' values?

+3  A: 

Placing an additional checkbox labeled something like "enable notification" that enables / disables the DateTimePicker.

Serhat Özgel
+4  A: 

Here is an interesting article on CodeProject. The author has overridden the Value property to accept Null value as DateTime.MinValue, while maintaining the validation of MinValue and MaxValue of the standard control. That's all there's to it.

splattne
Yes Mr Grazoli's NullableDateTimePicker does do the job although I think that someone should review it and try and get rid of those ugly WndProc calls
Calanus
+2  A: 

Tri's solution did not quite cut it for me and so thought Mr. Grazioli and he did something about it: http://www.codeguru.com/csharp/csharp/cs_controls/custom/article.php/c9645

+7  A: 

You don't need to modify it to do this.

The DateTimePicker in .net actually has a checkbox built-in.

Set the ShowCheckBox property to true.

Then you can use the Checked property to see if the user has entered a value.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.showcheckbox(VS.80).aspx

Jan Obrestad
Thanks. This is much better than used a custom widget. It's what I was looking for and what probably would've worked for the original poster as well.
16bytes