Calendar control question

D

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?
 
M

Mark Rae

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());
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top