I have a masked text box bound to a nullabe datetime, but when the date is blanked out, the validation on the masked text box won't complete. Is there a way to force this behaviour? I want a blanked out text box to equal a null DateTime.
When the textbox is already null, the validation works. It only breaks when there is a date already bound and I try to blank it out.
I use this with
maskedtextbox
fordatetime
typeif need
null
date value, use nullable datetime type in class declaration :Experimenting with this i finally found an easier solution to this.
STEP 1:
Search the line that is binding your maskedtextbox (mine's called "mTFecha") in your Form.Designer.cs. i.e:
STEP 2:
Apply a minor hack:
You're Done!
I figured out it didn't have to do with the validation. It was when the date was being parsed back to the datetime.
This may not be the most elegant way to do this, but it does work. If anyone knows a better way, please let me know.
I have this code now.
You can simply give date format as below:
This should work: