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

how to set CURRENT date/time of schedule control

Hi, If I navigate away from the current datetime using the side calendars, how can I programatically reset back to current datetime, or to any datetime if I needed to?

I don't want to have to click on the navigator panel controls.

5 Replies

AR Arulpriya Ramalingam Syncfusion Team October 22, 2019 10:26 AM UTC

Hi David, 
 
Thanks for using Syncfusion products. 
 
The dates can be moved at run time by changing the DateValue of the Calender to the date that needs to be moved. Please make use of the below code and sample and in the sample, the date is moved based on the date in the DateTimePicker controls date when the Go button is clicked. 
 
Code example 
 
private void btnGoto_Click(object sender, EventArgs e) 
{ 
    DateTime newDate = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day); 
    //To navigate dates at run time. 
    scheduleControl1.Calendar.DateValue = newDate; 
    scheduleControl1.Refresh(); 
} 
 
 
Please get back to us, if you need any further assistance. 
 
Regards, 
Arulpriya 



DA DAVID October 22, 2019 11:34 AM UTC

Hi,

unfortunately this does not fully work, the side calendar does change ok but the main schedule display ie: week, month or day view is not updated.
I have played around and can not see an easy way to force the main display areas to sync with the nav calendar programatically


AR Arulpriya Ramalingam Syncfusion Team October 22, 2019 01:39 PM UTC

Hi David, 
 
Thanks for the update. 
 
We have analyzed the use case at our end and suspect that you are trying to switch the DayView with the selected date when the date is changed at run time. This can be achieved by using the SwitchToScheduleViewTypeDay() method by parsing the date to be viewed. We have modified the sample as per your requirement. Please make use of the below code and sample. 
 
Code example 
 
DateTime newDate = new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, dateTimePicker1.Value.Day); 
//To switch to day view when the date is selected programmatically. 
scheduleControl1.SwitchToScheduleViewTypeDay(newDate); 
 
 
Please get back to us with simple screenshots with issue replication procedures, if we misunderstood your use cases. 
 
Arulpriya 



DA DAVID October 22, 2019 01:51 PM UTC

Hi,

Thank you for your support

scheduleControl1.SwitchToScheduleViewTypeDay(newDate);  --- Does work.

But also need 

scheduleControl1.SwitchToScheduleViewTypeWeek(newDate)

scheduleControl1.SwitchToScheduleViewTypeMonth(newDate)

I have looked for these but they don't seem to have been implemented


AR Arulpriya Ramalingam Syncfusion Team October 23, 2019 01:57 PM UTC

Hi David, 
 
Thanks for the update. 
 
In order to switch between views, the PerformSwitchToScheduleViewTypeClick() method can be used and the specified date can be moved by setting the DateValue property of the Calendar. We have modified the sample based on your requirement and please make use of the below code and sample. 
 
Code example 
 
private void btnGoto_Click(object sender, EventArgs e) 
{ 
    if (this.dateTimePicker1.Value != this.scheduleControl1.Calendar.DateValue) 
    { 
        DateTime date = this.dateTimePicker1.Value; 
        int monthDiff = ((date.Year - this.scheduleControl1.Calendar.DateValue.Year) * 12) + date.Month - this.scheduleControl1.Calendar.DateValue.Month; 
        this.scheduleControl1.Calendar.DateValue = date; 
        this.scheduleControl1.Calendar.AdjustSelectionsByMonth(monthDiff > 0 ? monthDiff - 1 : monthDiff + 1); 
        var method = this.scheduleControl1.GetScheduleHost().GetType().GetMethod("SetCurrentCellInView", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); 
        if (method != null) 
        { 
            this.scheduleControl1.GetScheduleHost().Model.ResetCurrentCellInfo(); 
            method.Invoke(this.scheduleControl1.GetScheduleHost(), new object[] { date }); 
        } 
        this.scheduleControl1.PerformSwitchToScheduleViewTypeClick(ScheduleViewType.WorkWeek); 
    } 
} 
  
 
Please get back to us, if you need any further assistance. 
 
Regards, 
Arulpriya 


Loader.
Up arrow icon