-1

I have several date fields in my database table which allow NULL. I need to bind these columns to fields to my form. They DateTimePicker won't even show a blank/NULL as read from the database. It only shows the current datetime as set in the Value property of the datetimepicker object. The MaskedTextBox will show empty when it reads NULL data but it locks you in the field if you try to tab through it or clear data.

I cannot use any controls from a third party and I am not allowed to create my own controls. Is it really 2019 and Microsoft still refuses to address nullable dates? Do I have any recourse here other than using a standard, unmanaged textbox?

I'm not holding out a lot of hope based on my net searches but maybe someone can help. Thank you!

GunnerFan420
  • 198
  • 1
  • 12
  • 1
    `I am not allowed to create my own controls.` That's an odd requirement. WinForms has not been in active development for like a decade now. It's only maintained. – LarsTech Apr 24 '19 at 18:03
  • 2
    "I am not allowed to create my own controls." - Problem solved. The form you are trying design is a custom control; stop all work as it is not allowed. – TnTinMn Apr 24 '19 at 18:06
  • You could add a checkbox to enable or disable the control. The checkbox would take care of the nullable part while the textbox would take care of the value. – the_lotus Apr 24 '19 at 18:09
  • Looks like you have the answer [here][1]: https://stackoverflow.com/questions/846395/how-can-i-make-a-datetimepicker-display-an-empty-string – Itai Apr 24 '19 at 18:27

1 Answers1

-1

If you are DataBinding then something like this should work:

    With DateTimePicker1
        .CustomFormat = " "
        .Format = DateTimePickerFormat.Custom
    End With
    DateTimePicker1.DataBindings.Add("Value", dt, "DateCol", True, DataSourceUpdateMode.OnValidation, DBNull.Value)
    MaskedTextBox1.DataBindings.Add("Text", dt, "Col1", True, DataSourceUpdateMode.OnValidation, DBNull.Value)
Mr. Tripodi
  • 809
  • 1
  • 6
  • 7