Hide Weekend (Sat and Sun) in Winforms RadCalendar

7 posts, 0 answers
  1. Tony
    Tony avatar
    1 posts
    Member since:
    Mar 2008

    Posted 02 Jul 2008 Link to this post

    Can someone explain how I can hide Saturday and Sunday columns in the RadCalendar for WinForms?

    I have seen a code sample for AJAX, but I can see how to implement the same function in WinForms.

    If hiding the columns isn't possible, how about  disabling them??

    Thanks in advance for any help.

  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 03 Jul 2008 Link to this post

    Hello Tony,

    Currently, there is no propery in RadCalendar by which you can automatically hide the columns for the days of the weekend. However, I prepared a sample solution to demonstrate a workaround. You should traverse the CalendarTableElement which contains the CalendarCellElements of interest. Then, for those cellelements which represents days of the weekend, set the Visibility property to Hidden.

    If you have additional questions, feel free to contact me.

    All the best,
    Nikolay
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    14 posts
    Member since:
    Mar 2008

    Posted 15 Sep 2008 Link to this post

    Tony, sorry for snaking your thread....  

    Nikolay, 
        this is great solution for a single calendar, but I cannot figure how to disable weekends for a multimonth view.

    Could you possibly expand on the provided workaround to do this?


    TIA,
    Mike
  5. Mike
    Mike avatar
    14 posts
    Member since:
    Mar 2008

    Posted 15 Sep 2008 Link to this post

    After some messing with the Element Hierarchy editor i managed to come up with a valid way to handle this for multimonth views.

    Below is the code i used. Hope this helps someone else in the future.


    private void DisableWeekends()  
    {  
        RadCalendarElement calElement = rcalTripDates.RootElement.Children(0) as RadCalendarElement;  
        MultiMonthViewElement calMultiMonthviewElement = calElement.Children(0).Children(2) as MultiMonthViewElement;  
        CalendarMultiMonthViewTableElement calMultiMonthViewTableElement = calMultiMonthviewElement.Children(0).Children(1) as CalendarMultiMonthViewTableElement;  
        foreach (MonthViewElement mvwElement in calMultiMonthViewTableElement.Children) {  
            CalendarTableElement calTable = mvwElement.Children(0).Children(1) as CalendarTableElement;  
            if (!calTable == null)  
            {  
                foreach (CalendarCellElement cell in calTable.Children) {  
                    if ((cell.Date.DayOfWeek == DayOfWeek.Saturday) || (cell.Date.DayOfWeek == DayOfWeek.Sunday) || (cell.Text == "S"))  
                    {  
                        cell.Enabled = false;  
                    }  
                }  
            }  
        }  
  6. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 16 Sep 2008 Link to this post

    Hello Mike,

    I think there is a better way to hide weekend days. CalendarCellElement has a property named WeekEnd. This will allow you to exclude the huge If statement.

     
    Regards,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Mike
    Mike avatar
    14 posts
    Member since:
    Mar 2008

    Posted 16 Sep 2008 Link to this post

    Boyko,

    thanks for the info... the huge IF statement is actually from the submitted project that Nikolay posted. I only added the extra nesting for the mutlimonthviews.

    I will try the Weekend property and see how that works out.
  8. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 16 Sep 2008 Link to this post

    Sounds great, Mike. Let me know if I can help you with something else regarding this control.

     
    All the best,
    Boyko Markov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top
UI for WinForms is Visual Studio 2017 Ready