DevComponents.com

How to select all days in week when week number is clicked in MonthCalendarAdv control

To select all week days when week number in MonthCalendarAdv is clicked handle ItemClick event and use following code:

private void monthCalendarAdv1_ItemClick(object sender, EventArgs e)
{
    DayLabel label = sender as DayLabel;
    // If day label is clicked and label is used to display week of year
    if (label != null && label.IsWeekOfYear)
    {
        // Ensure that multi-selection is enabled
        monthCalendarAdv1.MultiSelect = true;
        // Get the month control that represents the month that label is assigned to
        // so complete date can be retrieved
        SingleMonthCalendar month = label.Parent as SingleMonthCalendar;
        // Parse the week of year from text
        int week = int.Parse(label.Text);
        // Get the month where week of year clicked resides
        DateTime d = month.DisplayMonth;
        // Forward date to the beginning of the week
        while (CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(d, month.WeekOfYearRule, month.FirstDayOfWeek) != week)
            d = d.AddDays(1);
        // Finally select the week...
        monthCalendarAdv1.SelectionStart = d;
        monthCalendarAdv1.SelectionEnd = d.AddDays(6);
    }
}

Would you like to...

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favoritesAdd to favorites

User Opinions (3 votes)

66% thumbs up 33% thumbs down

How would you rate this answer?

Helpful
Not helpful
Thank you for rating this answer.

Related Questions

No related questions were found.

Attachments

No attachments were found.