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
close icon

I want to select a specific date from source code in the scheduler in windows forms;

hi. I want to select a specific date from source code in the scheduler;
I looked for various properties but couldn't solve them;
my example code)         private void btnToday_Click(object sender, EventArgs e)
        {
            //scdCtrl.Calendar.SelectedDates.Clear();
            scdCtrl.Calendar.DateValue = DateTime.Now; // 2019-08-08
            scdCtrl.GetScheduleHost().Calendar.DateValue = DateTime.Now;
        }         private void Calendar_DateValueChanged(object sender, EventArgs e)
        {
            DateTime firstSelectedTime = scdCtrl.Calendar.SelectedDates[0];     // ========> this date : 2019-09-01, i want "2019-08-08"
            SetViewRangeOfCalendar(firstSelectedTime.Year, firstSelectedTime.Month);
        } thank you;

Attachment: schedulegototoday20190808_1c795e2d.rar

9 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team August 8, 2019 11:31 AM UTC

Hi Smart, 
 
Thanks for using Syncfusion product.  
 
To move the selection programmatically, you can use the CurrentCell.MoveTo method after initialize the date value. Please refer the following code example and the sample.  
 
this.scheduleControl1.Calendar.DateValue = new DateTime(2019, 9, 8); 
this.scheduleControl1.Appearance.MonthShowFullWeek = true; 
this.scheduleControl1.GetScheduleHost().CurrentCell.MoveTo(2, 7); 
 
 
Please refer the below screen shot where the second row and seventh column is selected. 
 
 
 
In this above attached sample, MonthShowFullWeek property has enabled. If you have disabled this property, week days are covered by two rows. So, if you move to second row you could use the following code example.  
 
this.scheduleControl1.GetScheduleHost().CurrentCell.MoveTo(4, 7); 
 
Please refer the below forum for your reference. 
 
Note:  
To access the CurrentCell property, you could attach the Syncfusion.Grid.Windows.dll in your project. 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 



SL Smart law developer August 8, 2019 04:22 PM UTC

The sample you sent does not change to the date I specified.
What I need is the scheduler grid to change to the date I entered.


SL Smart law developer August 8, 2019 06:06 PM UTC

This works fine when you run the application, but if you change to a specific date during execution, the scheduler's date does not change to the desired date.

I attached the example project to the attached file,
I explained in screenshots what I needed.

Please solve.

Attachment: Schedule_Sample1030468972_8c04dc87.rar


JP Jagadeesan Pichaimuthu Syncfusion Team August 9, 2019 11:21 AM UTC

Hi Smart, 
 
Thanks for your update. 
 
We have checked your requirements and modified the sample based on your scenarios. Please find the attached sample and let us know if you have any other queries. 
 
1. Code to update the month view and set the focus to selected date: 
private void btnGoto_Click(object sender, EventArgs e) 
{          
    DateTime date = this.dateTimePicker1.Value; 
    int monthDiff = date.Month - this.scheduleControl1.Calendar.DateValue.Month; 
    this.scheduleControl1.Calendar.DateValue = date; 
    this.scheduleControl1.Calendar.AdjustSelectionsByMonth(monthDiff > 0 ? monthDiff - 1 : monthDiff + 1); 
    this.scheduleControl1.ResetProvider(this.scheduleControl1.ScheduleType); 
    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 }); 
    } 
} 
 
2. Code to update the current month and set focus in NavigationPanel calendar: 
scheduleControl1.Calendar.CalenderGrid.QueryCellInfo += CalenderGrid_QueryCellInfo1; 
 
private void CalenderGrid_QueryCellInfo1(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e) 
{ 
    DateTime day = this.dateTimePicker1.Value; 
    DateTime isdate; 
    if (!string.IsNullOrEmpty(e.Style.CellValue.ToString()) && DateTime.TryParse(e.Style.CellValue.ToString(),out isdate) && 
        isdate == day) 
    { 
        e.Style.BackColor = this.scheduleControl1.Appearance.NavigationCalendarTodayBackColor; 
        e.Style.TextColor = this.scheduleControl1.Appearance.NavigationCalendarTodayTextColor; 
    } 
} 
 
Sample link: 
 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan 



SL Smart law developer August 10, 2019 09:39 AM UTC

Thank you for the sample you sent us.
When I press the "Go" button in that sample, it sometimes moves to that date, but most attempts do not move to the date indicated by the datetimepicker.
Attach the sample you sent me, and attach the video I played.
Please debug;

Attachment: Scheduler_20190810_182903_e540fbb.rar


KA Keerthivasan Asokkumar Syncfusion Team August 12, 2019 12:56 PM UTC

Hi Smart,

Thanks for your update.

We have analyzed the sample and resolved the reported issue. Please find the attached sample and let us know if you have any other queries.

Please replace old code with highlighted changes in your sample.

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 });

                }

            }

}


Sample link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/ModifiedSample2123389811.zip

Let us know whether this helps you and also if you need any further assistance on this.

Regards,

Keerthivasan A.



SL Smart law developer September 10, 2019 03:31 PM UTC

Hi;
I write after a long time.
I couldn't do scheduler coding because of other urgent work.
I tested it with the sample code you sent me last.
The conclusion is not correct.
Attach a video.
It should be coded in detail.
Thank you. ps. my email address : "kim" newmanjoo@nate.com

Attachment: Scheduler_20190911_001407_51e50953.rar


AR Arulpriya Ramalingam Syncfusion Team September 11, 2019 02:55 PM UTC

Hi Smart, 
 
Thanks for your update. 
 
We could reproduce the issue at our end and we are working on this with high priority. We need some more time to validate the use case at our end and we will update you the proper details on 13th September, 2019. 
 
Regards, 
Arulpriya 



AR Arulpriya Ramalingam Syncfusion Team September 15, 2019 08:36 AM UTC

Hi Smart, 
 
Thanks for your patience. 
 
We have analyzed the reported use case at our end with the sample and it occurred due to the AdjustSelectionsByMonth() method was not updated properly when the DateValue is changed manually through the button click. In order to overcome this use case, the label of header text can be updated properly by using the AdjustSelectionsByMonth() method. We have modified the sample based on your requirement and please make use of the below code and modified sample. 
 
Code example 
 
private void Calendar_DateValueChanged(object sender, EventArgs e) 
{ 
        DateTime firstSelectedTime = scheduleControl1.Calendar.SelectedDates[0]; 
    SetViewRangeOfCalendar(firstSelectedTime.Year, firstSelectedTime.Month); 
    DateSelections SelectedDates = scheduleControl1.Calendar.SelectedDates; 
    //To update the headertext label 
    if (SelectedDates[SelectedDates.Count - 1] > scheduleControl1.Calendar.BottomRightDate.AddDays(-1)) 
    { 
        this.scheduleControl1.Calendar.AdjustSelectionsByMonth(-1); 
    } 
} 
 
 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon