Version 2.2.41.0 Dev broke my DateTimePicker

Answered
0
0

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)

  • You must to post comments
Great Answer
0
0

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)
  • You must to post comments
0
0

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

 

 

  • Luca
    • Luca
    • Mar 9, 2021 - 12:51 pm
    • 1
    You can override the Value property and change the value in set { } before calling base.Value = value. Otherwise changing the Value in OnValueChanged triggers another ValueChanged event.
  • Ivan Borges
    Great! This is it. Thank you, Luca.
  • Ivan Borges
    Hey Luca. Value is not overridable. Any trick on this one?
  • You must to post comments
0
0

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?

  • Ivan Borges
    Yep, YUC ( had to Google IIUC :-) ).
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.