Hi.
I have a custom DateTimePicker which will show an empty content on a Date Value (1800-01-01). So, I have it tested inside its ValueChanged and set its CustomFormat to ” ” in order to accomplish that. Since this last version, whenever this happens the Date Value is changed to 0001-01-01 which breaks my “null” value logic (no NULLS accepted for dates in Database, 1800-01-01 means NULL).
Any chance for this to go back as it was? 🙂
Cheers.
Ivan
(Wisej 2.2.41.0 – C# – SQLServer)
If yes, try this:
public class MyDateTimePicker : DateTimePicker { private static readonly DateTime NULL_DATE = new DateTime(1800, 1, 1); protected override string GetDisplayText(DateTime? value) { if (value == NULL_DATE) return ""; return base.GetDisplayText(value); } }
You can display anything you want for any value and parse anything you need if you also override
protected override bool ParseEditText(string text, out DateTime value)
Hi Luca.
Thank you so much for the prompt reply!
Yes, I had something similar to that in my custom DateTimePicker, but overriding the GetDisplayText is a lot better, since I was dealing with everything inside the ValueChanged. However, when the user leaves the field blank it is still setting the Value to 01/01/0001, so in order to be able to DataBind to this control I have created a ValueToBind property and setting it to 01/01/1800 whenever the ValueChange brings a value <= 01/01/1800 and then I bind to this new property in the forms. Hope it makes sense. 🙂
Cheers.
Ivan
IIUC the database has no nulls and 1800-1-1 is considered by the app to be null so when the user leaves the field blank you want to write 1800-1-1 instead of null and when 1800-1-1 coming from the database you want to display an empty datetimepicker?
Please login first to submit.