I want to clear my datetimepicker object value when i click on the clear button.
I just tried like this:
datetimepicker1.Format = DateTimePickerFormat.Short;
datetimepicker1.CustomFormat = " ";
Yes,it is cleared the value under the datetimepicker control. But the problem is after cleared the value then, I want to select the date after selection of the particular date, that date will not be displayed into datetimepicker object. What's the issue?
This should meet your purpose. Logic is to reset date to minimum and then use ValueChanged
event to hide it in display using what you already tried.
private void DateTimePicker1_ValueChanged(object sender, EventArgs e)
{
if (dateTimePicker1.Value == DateTimePicker.MinimumDateTime)
{
dateTimePicker1.Value = DateTime.Now; // This is required in order to show current month/year when user reopens the date popup.
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = " ";
}
else
{
dateTimePicker1.Format = DateTimePickerFormat.Short;
}
}
private void Clear_Click(object sender, EventArgs e)
{
dateTimePicker1.Value = DateTimePicker.MinimumDateTime;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With