Articles in this section
Category / Section

How to set the backcolor for all appointment dates in 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 Schedule 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.

Apply back color of appointment dates

Figure 1: Apply back color of appointment dates

Samples: Appointment_Backcolor

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied