Hi.
I have a legacy database where all DateTime columns have the date 01/01/1800 meaning “Null” dates. So, no null is allowed and when we want to mean a datetime is empty, 01/01/1800 is saved on its place.
Then we had DateTime controls that would show empty when the content was 01/01/1800 and set 01/01/1800 when the user cleared the control content.
In our Wisej DateTimePicker, I thought that if I set the MinDate to this 01/01/1800 date I would be done with it, but it doesn’t seem to work this way. Moreover, if I clear the DateTimePicker content at run-time, which is bound to a DateTime property, I get the control have a red border not accepting it to be empty.
Would there be a trick to be able to first, be able to empty the DateTimePicker content, and second, make it set its Value to 01/01/1800 once cleared?
Thanks in advance.
Ivan
(VS 2019, C#, Wisej 2.2.38.0)
Ivan,
You can use this in the DropDown event that Alaa mentioned.
this.dateTimePicker1.Eval($”this.getChildControl(‘list’).setValue(new Date(‘{new DateTime(2021,1,15).ToString(“yyyy-M-d”)}’))”);
Or you can use the NullableValue property and set it to null or set Text to “”. The DateTime.MinValue is 1/1/0001 so 1800 is a valid date.
HTH
Hi Ivan,
When you said that you want to “clear” the DateTimePicker, do you mean that you want to set the value of the control to be empty or just show the desired date?
If that’s what you’re looking for I have attached a file to what could be a resolution to your problem.
If that’s not the case, can you please provide me with some more information?
Maybe you’re using some UserControls?
Best regards,
Alaa
Thank you Luca!
It worked like a charm.
I was trying to set the control.Value at the DropDown. Using your JS was exactly what I needed.
I tried using the NullableValue to start with, but got many exceptions thrown while doing that. Maybe I didn’t do it the proper way. I will check further.
Hi again, Alaa.
I was able to accomplish showing a blank box on a pre-set datetime using the Custom Format.
Now I have a side-effect, which happens once the user goes to the control to Enter some date. All fine if they type it, but if they choose to use the Calendar tool on the box, it will show a date way behind, in 01/01/1800. 😀
OK, this might be one of those “you can’t have the cake and eat it too”, but would you know of a way to set this Calendar to Todays date programmatically when the user enters it, if necessary?
Hi Alaa.
Thanks so much for the reply.
Sorry, with “clear” I meant the control to be empty. So, if the user empties its content, what would be a NULL date, I want its bound property to be set to 01/01/1800. On the other hand, if the property value returns 01/01/1800, I would like the control to show an empty space, and of course, let the user type or choose any date they want.
And no, so far I am not using any UserControl for this.
I can be confusing at times (most of them), so ask me anything you want to make it clear. 🙂
Please login first to submit.