Very strange, I tried to reproduce your problem, and when I switch from March to February, my control just doesnβt display anything ... Maybe we have different versions of the frameworks that handle the same error in different ways.
In any case, one of the solutions would be to set the date and time collector on the first of each month, and when you need this value, you can simply use your code in the form in which it is now:
DateTime lastDayOfMonth = new DateTime( selectedDate.Year, selectedDate.Month, DateTime.DaysInMonth(selectedDate.Year, selectedDate.Month));
Since you never use the daily value of your datitude assistant, you can simply set it to 1, which will always give the existing date.
This decision leaves me somehow bad, because you are using a date that is different from the date you get from your control - always a possible source of errors, IMO. Remember to add comments to your code explaining why you are doing this; -)
source share