Week selections like in MS Outlook

3 posts, 0 answers
  1. Danny Scheelings
    Danny Scheelings avatar
    69 posts
    Member since:
    Jan 2006

    Posted 22 Jul 2010 Link to this post

    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. Danny Scheelings
    Danny Scheelings avatar
    69 posts
    Member since:
    Jan 2006

    Posted 22 Jul 2010 Link to this post

    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
  3. DevCraft banner
  4. George
    Admin
    George avatar
    1332 posts

    Posted 27 Jul 2010 Link to this post

    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
Back to Top