| View previous topic :: View next topic |
| Author |
Message |
John Blackburn Guest
|
Posted: Sun Feb 12, 2006 5:03 pm Post subject: Using TDateTimePicker for dates only |
|
|
I am trying to use TDateTimePicker for picking pure dates and I have a
couple of problems.
The first problem is with the following statement :-
DatePicker->Date = DatePicker->MaxDate;
The problem is that it can't manage this and ends up setting the Date of the
TDateTimePicker to the minimum date instead. I suspect it is because of the
Time part of the date causing the Picker to think that I am attempting to
set the Date beyond the MaxDate. What is the recommended way to use the
TDateTimePicker object for pure dates ?
My second problem is the little red circle at the bottom of the calendar
drop down which allows you to select today's date. The date range I am
attempting to use for the selection of dates does not encompass today's
date. Is there any way to turn this feature (which is normally very useful)
off ?
Many Thanks for any input
John |
|
| Back to top |
|
 |
HF Guest
|
Posted: Sun Feb 12, 2006 10:03 pm Post subject: Re: Using TDateTimePicker for dates only |
|
|
I tried this code and is working
Will catch the EDateTimeError as expected
Be sure DateTimePicker1->Kind = dtkDate
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
DateTimePicker1->MaxDate = StrToDate("10/10/2009");
try{
DateTimePicker1->Date = StrToDate("10/11/2009");
}
catch(EDateTimeError &e){
ShowMessage(e.Message);
}
}
//---------------------------------------------------------------------------
-minas |
|
| Back to top |
|
 |
John Blackburn Guest
|
Posted: Mon Feb 13, 2006 1:03 pm Post subject: Re: Using TDateTimePicker for dates only |
|
|
| Quote: | The first problem is with the following statement :-
DatePicker->Date = DatePicker->MaxDate;
|
I've checked DatePicker->MaxDate and it is equal to 39386 (no fractional
part).
I've even tried :-
DatePicker->Date = (int)DatePicker->MaxDate;
and it still won't take it - is this a known problem ? |
|
| Back to top |
|
 |
John Blackburn Guest
|
Posted: Mon Feb 13, 2006 1:03 pm Post subject: Re: Using TDateTimePicker for dates only |
|
|
Thanks, I appreciate the reply; however, I'm looking for a cleaner solution
and I do need to be able to use the last day of the range. |
|
| Back to top |
|
 |
Thorsten Kettner Guest
|
Posted: Mon Feb 13, 2006 3:03 pm Post subject: Re: Using TDateTimePicker for dates only |
|
|
"John Blackburn" <johnNOSPAM (AT) PLEASElintonhealy (DOT) co.uk> wrote:
| Quote: | I am trying to use TDateTimePicker for picking pure dates and
I have a couple of problems.
The first problem is with the following statement :-
DatePicker->Date = DatePicker->MaxDate;
|
Yes, it seems that there is a bug in TDateTimePicker and you
cannot set Date = MaxDate programmatically. Maybe it's time to
look for a third party component. (TProfDateTimePicker is free
and good but doesn't solve this particular problem. I've just
checked this. But maybe there are others that do).
| Quote: | My second problem is the little red circle at the bottom of
the calendar drop down which allows you to select today's
date. [snip] Is there any way to turn this feature (which is
normally very useful) off ?
|
In the DropDown event you can access the calender's handle and
change its style:
void __fastcall TForm1::DateTimePicker1DropDown(TObject *Sender)
{
HWND CalendarHandle = DateTime_GetMonthCal(DateTimePicker1->Handle);
int CalStyle = GetWindowLong(CalendarHandle, GWL_STYLE);
SetWindowLong(CalendarHandle, GWL_STYLE, CalStyle | MCS_NOTODAY | MCS_NOTODAYCIRCLE);
} |
|
| Back to top |
|
 |
HF Guest
|
Posted: Mon Feb 13, 2006 3:03 pm Post subject: Re: Using TDateTimePicker for dates only |
|
|
From C++ Builder Help :
Description
Assign a value to MaxDate to limit the range of dates that the user can
enter.
If you don't assign a value then that date is equal to 30 Dec 1899 .The same
for MinDate
-minas |
|
| Back to top |
|
 |
John Blackburn Guest
|
Posted: Mon Feb 13, 2006 6:03 pm Post subject: Re: Using TDateTimePicker for dates only |
|
|
Thanks Thorsten,
Amazing such a basic object has such a bug in it. However, I think I
will stick with this one as I found that the following works :-
RenewalDate->MaxDate = RenewalDate->MaxDate+1;
RenewalDate->Date = RenewalDate->MaxDate-1;
RenewalDate->MaxDate = RenewalDate->MaxDate-1;
Worth remembering !
Also, thanks for the bit of lower level code to help me get rid of the
today circle in the drop down; it works fine.
Regards
John |
|
| Back to top |
|
 |
|