Home All Groups Group Topic Archive Search About

Calendar control question

Author
24 Dec 2005 2:00 PM
DougS
Is it possible to highlight more than one date in the calendar control? I'm
trying to display a calendar to the user and highlight the dates that have
action items. Is this possible? Or is this control just for selecting dates?

Author
24 Dec 2005 2:19 PM
Mark Rae
"DougS" <doug@nospam.com> wrote in message
news:4wcrf.2524$Or5.684@tornado.southeast.rr.com...

> Is it possible to highlight more than one date in the calendar control?
> I'm trying to display a calendar to the user and highlight the dates that
> have action items. Is this possible? Or is this control just for selecting
> dates?

You need to investigate the DayRender event, which fires once per day
displayed in the calendar control's current view. You work out which day it
is by the Day property of the DayRenderEventArgs parameter.

E.g. I maintain an online calendar for several bands, showing dates of
rehearsals, gigs etc. First I query SQL Server for any "events" which fall
between the beginning and end dates of the calendar's current view and read
them into an ArrayList. Then it's a simple matter to highlight any day on
which the band has an "event", as follows:

  public void DayRender(object source, DayRenderEventArgs e)
  {
   if (arrDates.ContainsKey(e.Day.Date.ToString("dd MMM yyyy")) &&
!e.Day.IsOtherMonth)
   {
    Array arrStyle = arrDates[e.Day.Date.ToString("dd MMM
yyyy")].ToString().Split((Convert.ToChar(";")));
    e.Cell.Font.Bold = true;
    e.Cell.ForeColor =
System.Drawing.Color.FromName(arrStyle.GetValue(0).ToString());
    e.Cell.BackColor =
System.Drawing.Color.FromName(arrStyle.GetValue(1).ToString());
   }
  }

AddThis Social Bookmark Button