We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: ScheduleControl |
Published Date: September 12, 2018 |
Last Revised Date: June 24, 2021
Tags: week

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile