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

Click on weeknumber -> change to Worweek view

Hi,

when one clicks the week number in the calendar, the week is displayed in the ScheduleViewType.Week.
Is it possible to change this behaviour, so that the view type is ScheduleViewType.WorkWeek instead?

Thank you for you help.

Samy Abou-Shama

7 Replies

AD Administrator Syncfusion Team October 10, 2007 01:45 PM UTC

There is no event or property you can set to get this behavior.

So for now, you would have to get at the embedded GridControl that is in the NavigationCalendar. This requires deriving the ScheduleControl, NavigationCalendar and GridControl. You need to derive the first 2 classes just to create the proper instance of the latter 2 classes.

Inside the GridControl, you would override OnClick and catch the clicks there. If the click is on the month header, you would switch to the MonthView and if the click is on the week number, you would switch to the workweek view. In both cases, you set e.Cancel = true and not call the base class to prevent the default behavior from occurring. It takes little work to do this. Here is a minimal sample that attempts it.


SampleSchedule.zip


FB Felix Bagur September 4, 2018 09:15 AM UTC

In the current version there is a simpler solution? I have tried the example but it does not work correctly.

Thanks!,
Felix


MG Mohanraj Gunasekaran Syncfusion Team September 5, 2018 12:49 PM UTC

Hi Felix,  
  
Thanks for using Syncfusion product.  
  
To avoid the view changing while clicking on the week number, you could disable the SwitchViewStyle property. Please refer the following code example,  
  
Code example  
//To handle the view changing of scheduleControl.  
this.scheduleControl1.SwitchViewStyle = false;  
  
If you want to change the schedule view using ScheduleControl context menu. You could use the CalenderGrid.MouseDown and ScheduleContextMenuClick event to handle the SwitchViewStyle property. Please refer the following code example and the sample,  
  
Code example  
this.scheduleControl1.Calendar.CalenderGrid.MouseDown += CalenderGrid_MouseDown;  
this.scheduleControl1.ScheduleContextMenuClick += ScheduleControl1_ScheduleContextMenuClick;  
private void ScheduleControl1_ScheduleContextMenuClick(object sender, ScheduleContextMenuClickEventArgs e)  
{  
    if (!this.scheduleControl1.SwitchViewStyle)  
        this.scheduleControl1.SwitchViewStyle = true;  
}  
  
private void CalenderGrid_MouseDown(object sender, MouseEventArgs e)  
{  
    this.scheduleControl1.SwitchViewStyle = false;  
}  
  
  
Mohanraj G 



FB Felix Bagur September 5, 2018 12:57 PM UTC

Thanks for your quick response,

The problem comes when you click on the week number, not on a calendar day. 

Clicking on the week number keeps changing to the whole week even if you have disabled SwitchViewStyle.

I would like to be able to click on a day of the calendar and get the daily view and click on the week number and get the work week.

Thanks a lot,

Fèlix



AA Arulraj A Syncfusion Team September 6, 2018 09:15 AM UTC

 
Sorry for the inconvenience caused. 
 
To avoid the view changing while clicking on the week number, you could handle the CalendarGrid.CellClick event. Please refer the following code example and the sample, No need to disable the SwitchViewStyle property. 
 
Code example 
this.scheduleControl1.Calendar.CalenderGrid.CellClick += CalenderGrid_CellClick; 
 
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; 
    } 
} 
 
 
Arulraj A 



FB Felix Bagur September 12, 2018 07:16 AM UTC

Thanks for you update!, it works!
Fèlix


MG Mohanraj Gunasekaran Syncfusion Team September 12, 2018 08:58 AM UTC

 
Thanks for your update. 
 
We are glad to know that your reported problem has resolved. 
 
Please let us know if you have any concerns. 
 
Regards, 
Mohanraj G 


Loader.
Live Chat Icon For mobile
Up arrow icon