How to change .NET DateTimePicker control to allow null values?

What is the easiest and most reliable way to modify the .NET DateTimePicker control so that users can enter null values?

+20
null datetimepicker
Nov 12 '08 at 15:48
source share
6 answers

Here is an interesting article in a CodeProject article . The author has overridden the Value property to accept Null as DateTime.MinValue , while maintaining the validation of the MinValue and MaxValue of the standard control. It is all there.

+5
Nov 12 '08 at 15:56
source share

You do not need to modify it to do this.

DateTimePicker in.net really has a built-in checkbox.

Set the ShowCheckBox property to true .

You can then use the Checked property to find out if the user entered a value.

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

+46
Nov 19 '09 at 12:32
source share

Placement of an additional flag labeled "enable notification", which enables / disables DateTimePicker.

+4
Nov 12 '08 at 15:50
source share

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

+2
Dec 09 '08 at 13:54
source share

I posted my long solution path in which there are some finds in the code comments about specific problems with this control:

Zero DateTime Picker

0
Dec 23 '11 at 11:33
source share

Set the ShowCheckBox property to true. Then you can use the Checked property as follows:

 private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { DateTimePicker thisDateTimePicker = (DateTimePicker)sender; if (thisDateTimePicker.Checked == false) { thisDateTimePicker.CustomFormat = @" "; //space thisDateTimePicker.Format = DateTimePickerFormat.Custom; } else { thisDateTimePicker.Format = DateTimePickerFormat.Short; } } 
0
Oct 09 '15 at 6:26
source share



All Articles