简体   繁体   中英

How do I initialise DateTimePicker to Null or Empty?

How initialize a DateTimePicker to Null or Empty in windows forms?

I tried:

dtNascimento.Format = DateTimePickerFormat.Custom;
dtNascimento.CustomFormat = " ";

But then does not allow changing the value.

You can use the ShowCheckBox=true and Checked=false properties values to indicate that no (valid) date/time is selected. And you can combine it with the custom format on CheckedChanged event if you want to really show a blank value when the checkbox is cleared.

Its work

dtNascimento.CustomFormat = " ";
dtNascimento.Format = DateTimePickerFormat.Custom;

 private void dtNascimento_ValueChanged(object sender, EventArgs e)
 {
     dtNascimento.CustomFormat = "dd-MM-yyyy";
 }

Set Null value in DateTimePicker in C#

It is somewhat easy to extend the DateTimePicker control. Have a look at http://emoreau.com/Entries/Articles/2005/01/The-DateTimePicker-control.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM