Special Days help

2 posts, 1 answers
  1. Joe
    Joe avatar
    1 posts
    Member since:
    Nov 2012

    Posted 24 Jan 2013 Link to this post

    Hi

    I'm trying to retrieve a list of special days held in a table on an SQL server and use those dates as Special Days - how do I do this? I can retrieve the dates into, say, a dataset or gridview but I'm unclear how to then add these as Special Days at run time.

    Also I have some code I found that completely disables Sundays on the calendar. How can I adapt this so the same applies to any Special Days? I ask because the code completely greys out Sundays yet Special Days are still 'clickable' and I want them to also be greyed out.

    Here's the code:

     

     

     

     

    Dim calTable As Telerik.WinControls.UI.CalendarTableElement = TryCast(RadCalendar1.RootElement.Children(0).Children(0).Children(2).Children(0).Children(1), Telerik.WinControls.UI.CalendarTableElement)
            If calTable IsNot Nothing Then
                For Each cell As Telerik.WinControls.UI.CalendarCellElement In calTable.Children
                    If (cell.[Date].DayOfWeek = DayOfWeek.Sunday) Then
                        cell.Enabled = False
                    End If
                Next
            End If

    Thanks for any help
    Dan
  2. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 29 Jan 2013 Link to this post

    Hi Joe,

    You can add special days in RadCalendar by inserting them in the SpecialDays collection. Please note that all special days should have hours, minutes and seconds set to 0. Here is a sample:
    For Each row As DataRow In table.Rows
        Dim day As DateTime = DirectCast(row("Date"), DateTime)
        calendar.SpecialDays.Add(New RadCalendarDay(New DateTime(day.Year, day.Month, day.Day, 0, 0, 0)))
    Next

    In this example I assume that dates are contained in the Date column of a DateTable.

    Regarding your second question, you can use the same technique for special days. Consider the code below:
    Dim viewElement As MonthViewElement = DirectCast(calendar.CalendarElement.CalendarVisualElement, MonthViewElement)
    For Each cell As CalendarCellElement In viewElement.TableElement.Children
        If cell.SpecialDay Then
            cell.Enabled = False
        End If
    Next

    I hope this helps.
     
    Greetings,
    Jack
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top