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

Special Days help

1 Answer 107 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 24 Jan 2013, 03:27 PM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 29 Jan 2013, 01:13 PM
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.
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Joe
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or