This is a migrated thread and some comments may be shown as answers.

Week selections like in MS Outlook

2 Answers 65 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Danny Scheelings
Top achievements
Rank 1
Danny Scheelings asked on 22 Jul 2010, 12:58 PM
Hi,

I want to use week selections in the RadCalendar control, like Microsoft does in Outlook. So when a user clicks on a day in the calendar the whole week must automatically be selected. Offcourse I could handle the SelectionChanged event and then add all days in the current week to the SelectedDates collection, but I have to set the SelectionMode to Mutltiple or Extended for this to work. When the SelectionMode is set to one of these values, the user is able to multi-select the days in the calendar and that is what I want to prevent!

So the user must be able to select only one day in the calendar, but then automatically multiple days (from that week) must be selected.

Is there a way to perform this?

Thanks,
Danny

2 Answers, 1 is accepted

Sort by
0
Danny Scheelings
Top achievements
Rank 1
answered on 22 Jul 2010, 02:26 PM
Hi,

I just found a solution, but I would like to hear from a Telerik Admin if this is a good way to go, or if there are better ways. Below my code:
this.calendar.FirstDayOfWeek = DayOfWeek.Monday;
this.calendar.AreWeekNumbersVisible = true;
this.calendar.SelectionMode = Telerik.Windows.Controls.SelectionMode.Multiple;
this.calendar.SelectionChanged += new Telerik.Windows.Controls.SelectionChangedEventHandler(calendar_SelectionChanged);
  
private void calendar_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
    this.calendar.SelectionChanged -= new Telerik.Windows.Controls.SelectionChangedEventHandler(calendar_SelectionChanged);
  
    //Set current week selected
    DateTime date = (e.AddedItems.Count > 0 ? (DateTime)e.AddedItems[0] : this.calendar.SelectedDates[0]);
    this.calendar.SelectedDates.Clear();
    int weekDay = (int)new CultureCalendarInfo().GetDayOfWeek(date);
    int fromDay = (int)this.calendar.FirstDayOfWeek - weekDay;
    for (int i = fromDay; i < (fromDay + 7); i++)
    {
        DateTime dateToSelect = date.AddDays(i);
        this.calendar.SelectedDates.Add(dateToSelect);
    }
  
    this.calendar.SelectionChanged += new Telerik.Windows.Controls.SelectionChangedEventHandler(calendar_SelectionChanged);
}

In the SelectionChanged event handler, I remove the event handler and after setting the current week with SelectedDates I add the event handler again. Is this correct?

Thanks,
Danny
0
George
Telerik team
answered on 27 Jul 2010, 03:28 PM
Hi Danny Scheelings,

Thank you for contacting us.

The approach that you are using is the right one.

Thank you for suggesting this feature, it helps us in improving our products. If we receive enough clients' requests we will implement it. You can track this progress in our Public Issue Tracking System (PITS) with Issue ID = 2862.

Please do not hesitate to contact us if you require any further information.

Kind regards,
George
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Calendar
Asked by
Danny Scheelings
Top achievements
Rank 1
Answers by
Danny Scheelings
Top achievements
Rank 1
George
Telerik team
Share this question
or