Articles in this section
Category / Section

How to avoid changing the view while clicking on the week number in WinForms ScheduleControl?

1 min read

Handle the CellClick event

In order tTo avoid the view changing to Week view from WorkWeek view to Week view when clicking on the week number in calendar, enable the e.Cancel property in the CalendarGrid.CellClick event.

 

Code Ssnippet

C#

//Triggering the event
this.scheduleControl1.Calendar.CalenderGrid.CellClick += CalenderGrid_CellClick; 
 
//Handling the event
private void CalenderGrid_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e) 
{ 
    if (e.ColIndex == 1 && (this.scheduleControl1.ScheduleType == ScheduleViewType.WorkWeek || scheduleControl1.ScheduleType == ScheduleViewType.Day)) 
    { 
        GridStyleInfo style = this.scheduleControl1.Calendar.CalenderGrid[e.RowIndex, e.ColIndex]; 
        DateTime dateValue; 
        if (DateTime.TryParse(style.CellValue.ToString(), out dateValue)) 
        { 
            while (dateValue.DayOfWeek == DayOfWeek.Saturday || dateValue.DayOfWeek == DayOfWeek.Sunday) 
            { 
                //To get the week days of current week. 
                dateValue = dateValue.AddDays(1); 
            } 
 
            this.scheduleControl1.Calendar.SelectedDates.BeginUpdate(); 
            if (this.scheduleControl1.ScheduleType == ScheduleViewType.Day) 
                this.scheduleControl1.Calendar.SelectedDates[0] = dateValue; 
            else 
            { 
                this.scheduleControl1.Calendar.SelectedDates.Clear(); 
                this.scheduleControl1.Calendar.SelectedDates.Add(dateValue); 
            } 
            this.scheduleControl1.Calendar.SelectedDates.EndUpdate(); 
            this.scheduleControl1.GetScheduleHost().SwitchTo(ScheduleViewType.WorkWeek, true); 
        } 
        e.Cancel = true; 
    } 
} 

 

 

VB

‘Triggering the event
Private Me.scheduleControl1.Calendar.CalenderGrid.CellClick += AddressOf CalenderGrid_CellClick
 
‘Handling the event
Private Sub CalenderGrid_CellClick(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs)
    If e.ColIndex = 1 AndAlso (Me.scheduleControl1.ScheduleType = ScheduleViewType.WorkWeek OrElse scheduleControl1.ScheduleType = ScheduleViewType.Day) Then
        Dim style As GridStyleInfo = Me.scheduleControl1.Calendar.CalenderGrid(e.RowIndex, e.ColIndex)
        Dim dateValue As DateTime
        If DateTime.TryParse(style.CellValue.ToString(), dateValue) Then
            Do While dateValue.DayOfWeek = DayOfWeek.Saturday OrElse dateValue.DayOfWeek = DayOfWeek.Sunday
            'To get the week days of current week. 
            dateValue = dateValue.AddDays(1)
            Loop
                Me.scheduleControl1.Calendar.SelectedDates.BeginUpdate()
                If Me.scheduleControl1.ScheduleType = ScheduleViewType.Day Then
                    Me.scheduleControl1.Calendar.SelectedDates(0) = dateValue
                Else
                    Me.scheduleControl1.Calendar.SelectedDates.Clear()
     Me.scheduleControl1.Calendar.SelectedDates.Add(dateValue)
                End If
                Me.scheduleControl1.Calendar.SelectedDates.EndUpdate()
         Me.scheduleControl1.GetScheduleHost().SwitchTo(ScheduleViewType.WorkWeek, True)
        End If
        e.Cancel = True
    End If
End Sub

Sample link   s:

C#: AvoidViewChanging_CS

VB: AvoidViewChanging_VB

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