Windows and the Mysteriously BehaviorChanging Calendar Controls


  • Garbage Person

    So the Calendar Control available via .net WinForms apparently works somewhat differently depending on what version of Windows is installed. If you drag to select a range of dates, Windows XP sets the SelectionEnd to 00:00 on the last day of the range.

     Windows Vista and later, however, set SelectionEnd to 23:59:59.999 on the last day of the selection. This leads to Stupid. And cross-platform suckitude.

     

    if (Environment.OSVersion.Version.Major <= 5)
    {
    apptGrid.DataSource = (db.getAppointmentsDuringTime_HR(appointmentCalendar.SelectionStart, appointmentCalendar.SelectionEnd.AddHours(24)));
    }
    else
    {
    apptGrid.DataSource = (db.getAppointmentsDuringTime_HR(appointmentCalendar.SelectionStart, appointmentCalendar.SelectionEnd));
    }

     


  • Garbage Person

     Correction. Vista and above set it to 0:00:00 on the day FOLLOWING the last day of the selection. And none of this is documented, nor does anyone else seem to have noticed.


  • ♿ (Parody)

    Sounds like one of those, "Crap we did this wrong. Let's fix it and hope no one notices!"



  • @Weng said:

     Correction. Vista and above set it to 0:00:00 on the day FOLLOWING the last day of the selection. And none of this is documented, nor does anyone else seem to have noticed.

    That's how I define a date range in a DateTime type.. Is there a better way to do it at arbitrary precision?  So yeah, they fixed it.  Good to know that XP does it differently though.  I've missed a bullet on that one actually - came very close to deploying a calendar contorl on both platforms.  But I went with email distribution of spoonfed data instead of interactive, so I was able to eliminate the GUI.  Sweet.

     



  •  You don't have to check the OS version. What if they update the .NET framework to handle this logic for you? Maybe it would be better to do a check like if (date.time == 0:00) { date -= 1 second; }


  • Garbage Person

     Yeah, I agree the revised method is the correct one.

    I suspect the MonthCalendar control might have to be replaced entirely soon, because it's also a totally different size in Aero, which screws up all sorts of things.



  • Yeah, that really pissed me off too.  Do I size this for Aero or not?  There're other wierd differences too.


  • Garbage Person

    @hoodaticus said:

    Yeah, that really pissed me off too.  Do I size this for Aero or not?  There're other wierd differences too.

    Yep. The enlarged Aero version of the control doesn't correctly draw the selection if you set it programmatically.


Log in to reply