Topic: MonthCalendar

Hi,
I remember seeing an example of selecting multi dates using a MonthCalendar and transfer the start and end date to 2 DateTimePickers on the same form and saved to the database. I checked the forum but can't find it.

Cheers
Terry

Re: MonthCalendar

Hello.


procedure Form1_MonthCalendar1_OnClick (Sender: TObject);
begin
    Form1.DateTimePicker1.DateTime := Form1.MonthCalendar1.Date;
    Form1.DateTimePicker2.DateTime := Form1.MonthCalendar1.EndDate;
end;
Dmitry.

Re: MonthCalendar

Thanks for the quick reply. Is there any way to reproduce to the selected dates on the MonthCalendar  with a ShowRecord action. I get an error message saying that unable set dates. Thanks

Re: MonthCalendar

Hi Terry,
Is the attached the sort of thing that you mean?
Personally, I think it would be more readable if the highlighted colour extended across the entire selected date range rather than 'whiting it out' but I think that's something that Dmitry would have to review - I remember trying to change it a while ago but had no success.
Derek.

Post's attachments

Attachment icon terry 2 dates.zip 337.32 kb, 304 downloads since 2019-07-19 

Re: MonthCalendar

First you should enable property MultiSelect for the Calendar component

procedure frmAbonent_OnShow (Sender: TObject; Action: string);
begin
    if Action = 'ShowRecord' then
    begin
        frmAbonent.MonthCalendar1.Date := frmAbonent.DateTimePicker1.DateTime;
        frmAbonent.MonthCalendar1.EndDate := frmAbonent.DateTimePicker2.DateTime;
    end;
end;

procedure frmAbonent_MonthCalendar1_OnClick (Sender: TObject);
begin
    frmAbonent.DateTimePicker1.DateTime := frmAbonent.MonthCalendar1.Date;
    frmAbonent.DateTimePicker2.DateTime := frmAbonent.MonthCalendar1.EndDate;
end;
Dmitry.