Question

Background

We have a legacy forms based VB.NET application that is currently being redeveloped into an c# MVC web based application. I need to keep the forms based application going whilst this redevelopment happens. Throughout the application (hundreds of fields), we have used a control called nullableDateTimePicker (VBDateTimePicker.ProjectMentor.Windows.Controls.nullableDateTimePicker) as we needed a control that could handle a NULL date.

The problem

This control has worked fine for years, now however, it seems to have stopped working and when the control has a null value, choosing a date from the picker will not populate the picker. If the control has a date, the date will correctly change when selected from the picker. There must have been a windows update or some other environmental change that has kippered the control.

The question

  • In the NullableDateTimePicker.cs on the CodeProject source, we have the below:

    protected override void OnValueChanged(EventArgs eventargs)
    {
        base.OnValueChanged(eventargs);
    }
    

    However, this does not appear to update the value when chosen when the controls Value is set to null. The Demo project that comes from codeproject (linked above and below) exhibits the same broken behaviour on a patched Windows 7 / Windows 8 machine.

For ease of download, I have also popped the zipped project here on dropbox.

Was it helpful?

Solution

I would avoid overriding the WndProc method and just override the OnCloseUp method instead:

//protected override void WndProc(ref Message m)
//{
//  if (_isNull)
//  {
//    if (m.Msg == 0x4e)                         // WM_NOTIFY
//    {
//      NMHDR nm = (NMHDR)m.GetLParam(typeof(NMHDR));
//      if (nm.Code == -746 || nm.Code == -722)  // DTN_CLOSEUP || DTN_?
//        SetToDateTimeValue();
//    }
//  }
//  base.WndProc(ref m);
//}

protected override void OnCloseUp(EventArgs eventargs) {
  if (_isNull) {
    SetToDateTimeValue();
  }
  base.OnCloseUp(eventargs);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top