FIX: Cannot Simultaneously Set DTPicker's MinDate And MaxDate (198880)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q198880 SYMPTOMS
When you programmatically set the DateTimePicker's MinDate property, any current setting for the MaxDate property is lost. Conversely, setting the MaxDate property causes a loss of the MinDate's setting.
CAUSE
When an attempt is made to set either the MinDate or MaxDate properties, a SendMessage API call is made to send the " DTM_SETRANGE" message to the control to inform it of the new date range settings. This message can be used to set the date range in one of three ways:
- Establish a minimum date with no maximum date.
- Establish a maximum date with no minimum date.
- Establish both a minimum and maximum date.
The MinDate and MaxDate properties that are exposed to the Visual Basic programmer correspond directly to the first two methods. The DateTimePicker control does not offer any property that directly corresponds to the third method, thus leaving no way to set both a MinDate and a MaxDate at the same time through the control's object model.
This problem does not affect setting the MinDate and MaxDate properties at design time.
RESOLUTION
Because there is no exposed property or method for setting MinDate and MaxDate at the same time, a direct call to the SendMessage API must be made to manually send the "DTM_SETRANGE" message with the appropriate information.
The parameters for this message consist of setting wParam to represent the part(s) of the date range you are setting; "GDTR_MIN" for the minimum date, "GDTR_MAX" for the maximum date, or the combination of both constants for setting the minimum and maximum dates at the same time. The lParam must be set to point to a two element array of SYSTEMTIME structures. The first element is for specifying the minimum date information and the second element is for the maximum date information.
Modification Type: | Major | Last Reviewed: | 5/13/2003 |
---|
Keywords: | kbAPI kbBug kbCtrl kbfix kbVS600sp3fix KB198880 |
---|
|