Category / Section
How to set the backcolor for all appointment dates in the calendar in WinForms ScheduleControl?
1 min read
Set back color for appointment date
You can set the background color for all the appointment dates in WinForms Scheduler calendar by using PrepareViewStyleInfo event. Set the IScheduleDataProvider class to get the appointment data from the datasource.
C#
this.scheduleControl1.Calendar.CalenderGrid.PrepareViewStyleInfo += new Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventHandler(CalenderGrid_PrepareViewStyleInfo);
// to apply the style for appointment dates
void CalenderGrid_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
{
DateTime dt;
if (e.Style.Text.Length > 0 && DateTime.TryParse(e.Style.Text, out dt))
{
GridControl grid = sender as GridControl;
// to get appointment date from the datasource
IScheduleDataProvider dataProvider = this.scheduleControl1.DataSource;
IScheduleAppointmentList list = dataProvider.GetScheduleForDay(dt);
if (list.Count > 0 && (e.RowIndex != 0 && e.RowIndex !=8) )
{
// to apply the color for appointment
e.Style.BackColor = Color.Red;
}
}
}
VB
AddHandler scheduleControl1.Calendar.CalenderGrid.PrepareViewStyleInfo, AddressOf CalenderGrid_PrepareViewStyleInfo
' to apply the style for appointment dates
Private Sub CalenderGrid_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs)
Dim dt As DateTime
If e.Style.Text.Length > 0 AndAlso DateTime.TryParse(e.Style.Text, dt) Then
Dim grid As GridControl = TryCast(sender, GridControl)
' to get appointment date from the datasource
Dim dataProvider As IScheduleDataProvider = Me.scheduleControl1.DataSource
Dim list As IScheduleAppointmentList = dataProvider.GetScheduleForDay(dt)
If list.Count > 0 AndAlso (e.RowIndex <> 0 AndAlso e.RowIndex <> 8) Then
'to apply the color for appointment
e.Style.BackColor = Color.Red
End If
End If
End Sub
The following screenshot illustrates the output.
Figure 1: Apply back color of appointment dates
Sample Link: Appointment_Backcolor