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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to set CURRENT date/time of schedule control

Thread ID:

Created:

Updated:

Platform:

Replies:

148472 Oct 21,2019 05:09 PM UTC Oct 23,2019 01:57 PM UTC WinForms 5
loading
Tags: ScheduleControl
DAVID
Asked On October 21, 2019 05:09 PM UTC

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.

Arulpriya Ramalingam [Syncfusion]
Replied On 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 


DAVID
Replied On 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

Arulpriya Ramalingam [Syncfusion]
Replied On 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 


DAVID
Replied On 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

Arulpriya Ramalingam [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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
Live Chat Icon