Hi Terry,
You'd better not hard-code this 'freebee' special case value. You may use
DateTimePicker.MaxDate to get the allowable max date of DateTimePicker.
Regarding this magic value of 12/31/9998, yes, this is by design. If you
use the Reflector to view DateTimePicker.MaxDate property source code, you
will see:
public void set_MaxDate(DateTime value)
{
if (value != this.max)
{
if (value < EffectiveMinDate(this.min))
{
throw new ArgumentOutOfRangeException("MaxDate",
SR.GetString("InvalidLowBoundArgumentEx", new object[] { "MaxDate",
FormatDateTime(value), "MinDate" }));
}
if (value > MaximumDateTime)
{
throw new ArgumentOutOfRangeException("MaxDate",
SR.GetString("DateTimePickerMaxDate", new object[] {
FormatDateTime(MaxDateTime) }));
}
this.max = value;
this.SetRange();
if (this.Value > this.max)
{
this.Value = this.max;
}
}
}
As you can see, the property is bound by the MaximumDateTime property:
public static DateTime MaximumDateTime
{
get
{
return MaxDateTime;
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public static readonly DateTime MaxDateTime;
Finally, the MaxDateTime field is set in the DateTimePicker constructor:
static DateTimePicker()
{
DefaultTitleBackColor = SystemColors.ActiveCaption;
DefaultTitleForeColor = SystemColors.ActiveCaptionText;
DefaultMonthBackColor = SystemColors.Window;
DefaultTrailingForeColor = SystemColors.GrayText;
EVENT_FORMATCHANGED = new object();
MinDateTime = new DateTime(0x6d9, 1, 1);
MaxDateTime = new DateTime(0x270e, 12, 0x1f);
}
0x270e is just 9998 and 0x1f is 31. So the MaxDateTime field is initialized
to 12/31/9998 in the constructor code.
Anyway, we may use DateTimePicker.MaxDate to determine the max allowed date
without hard-code it. Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.