Description:
I'd like to provide my users with an "Event Count" indicator for each day in the weeks view of the scheduler. I'd like it to appear to the left of each day, left aligned and with a blue background.
Answer:
To implement this task you should handle the Scheduler’s OnCustomDrawContent event within this event you should do the following:
- Apply the default drawing to the content cell. This can be done by calling the Draw method of the AViewInfo parameter.
- Calculate the number of events for the current day. This can be done by calling the GetEvents method of the SchedulerStorage:
Delphivar
AList: TcxSchedulerFilteredEventList;
ACount, I: Integer;
...
AList := TcxSchedulerFilteredEventList.Create;
try
cxSchedulerStorage1.GetEvents(AList, AViewInfo.TimeStart,
AViewInfo.TimeFinish);
ACount := 0;
for I := 0 to AList.Count - 1 do
if AList[I].IsDayEvent(AViewInfo.TimeStart) then
Inc(ACount);
finally
AList.Free;
end;
- Draw the results on the content canvas:
DelphiACanvas.Brush.Style := bsClear;
if TcxSchedulerMonthDayContentCellViewInfo(AViewInfo).Selected then
ACanvas.Font.Color := TcxSchedulerMonthDayContentCellViewInfo(AViewInfo).SelectionTextColor
else
ACanvas.Font.Color := AViewInfo.TextColor;
with TcxSchedulerMonthDayContentCellViewInfoAccess(AViewInfo) do
ACanvas.DrawTexT('(' + IntToStr(ACount) + ')', Rect(Bounds.Left + 2, FTextRect.Top, FTextRect.Left, FTextRect.Bottom), cxAlignLeft or cxAlignVCenter);
ACanvas.Brush.Style := bsSolid;
And finally set the ADone parameter to True.
The attached project demonstrates how to accomplish this task.
See Also:
How to obtain the number of events scheduled for a given date