Link to home
Start Free TrialLog in
Avatar of Bob
Bob

asked on

How is the DateTimePicker "Cleared."

Been searching for the answer with no success. All I've read is how DateTime is not nullable. No explanation. It's probably due to it being a data structure, I guess.

What's needed is clearing the DTPs before a new doc is created. Since it's not nullable, how do you guys "clear" the DTP in VB.NET 2017?

Thanks for any help.

--Bob
Avatar of Shaun Kline
Shaun Kline
Flag of United States of America image

The DateTimePicker control has a Text and Value property. What happens when you set the Text property (string data type) to an empty string?

A different option would be to set the DateTimePicker to a default value (Today?).
Hi Bob,

https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/data-types/nullable-value-types

DateTime is nullable.

Now clearing a DatePicker, are you making a Desktop App or a WebApp?

Regards,
Chinmay.
you can handle it by using an empty CustomFormat as shown in  https://www.emoreau.com/Entries/Articles/2005/01/The-DateTimePicker-control.aspx
Avatar of Bob
Bob

ASKER

Thanks for the reply.

Shaun, when assigning an empty string to the text prop returns this odd message:

 User generated image
Chimnay, I understand now that it is nullable. It's for a desktop app.
That's an error in your code, not the date picker. Go to that function in your code--you're trying to access the value of a nullable object, but that object is null.

e.g.

DateTime? x = null;
DateTime y = x.Value;  // InvalidOperationException

Open in new window

Avatar of Bob

ASKER

Eric, this is the result. Maybe this doesn't work in WPF.

        dpMaintainenceDate.SelectedDateFormat = "yyyy/MM/dd"
        dpMaintainenceDate.Tag = ""

User generated image
Thanks for the help.
Avatar of Bob

ASKER

kaufmed, I understand your post. Thank you.

What's needed is to clear a DateTimePicker control. Any ideas on how to do this?

--Bob
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.