How to get the proper datetime while opening the appointment form in WorkWeek view in WinForms ScheduleControl?
Show the appointment form event
In order to get the proper start time and end time when the appointment form in WorkWeek view is opened in WinForms Schedule Control , the ShowingAppointmentForm event can be used. In that event, e.Item property can be used to get the proper schedule date and time.
C#
//Event subscription this.scheduleControl1.ShowingAppointmentForm += scheduleControl1_ShowingAppointmentForm; //Event Customization void scheduleControl1_ShowingAppointmentForm(object sender, ShowingAppointFormEventArgs e) { if (grid.CurrentCell.ColIndex > 0 && grid.SelectedAppointments.Count == 0) { int colIndex = this.GetUseTableFromCol(grid.CurrentCell.ColIndex); DateTime selctedDate = grid.Calendar.SelectedDates[colIndex]; IScheduleAppointment item = e.Item; item.StartTime = new DateTime(selctedDate.Year, selctedDate.Month, selctedDate.Day, e.Item.StartTime.Hour, e.Item.StartTime.Minute, e.Item.StartTime.Second); item.EndTime = new DateTime(selctedDate.Year, selctedDate.Month, selctedDate.Day, e.Item.EndTime.Hour, e.Item.EndTime.Minute, e.Item.EndTime.Second); Console.WriteLine("StartTime " + item.StartTime.ToString()); Console.WriteLine("EndTime " + item.EndTime.ToString()); } }
VB
'Event subscription AddHandler Me.scheduleControl1.ShowingAppointmentForm, AddressOf scheduleControl1_ShowingAppointmentForm 'Event Customization Private Sub scheduleControl1_ShowingAppointmentForm(ByVal sender As Object, ByVal e As ShowingAppointFormEventArgs) If grid.CurrentCell.ColIndex > 0 AndAlso grid.SelectedAppointments.Count = 0 Then Dim colIndex As Integer = Me.GetUseTableFromCol(grid.CurrentCell.ColIndex) Dim selctedDate As DateTime = grid.Calendar.SelectedDates(colIndex) Dim item As IScheduleAppointment = e.Item item.StartTime = New DateTime(selctedDate.Year, selctedDate.Month, selctedDate.Day, e.Item.StartTime.Hour, e.Item.StartTime.Minute, e.Item.StartTime.Second) item.EndTime = New DateTime(selctedDate.Year, selctedDate.Month, selctedDate.Day, e.Item.EndTime.Hour, e.Item.EndTime.Minute, e.Item.EndTime.Second) Console.WriteLine("StartTime" + item.StartTime.ToString()) Console.WriteLine("EndTime" + item.EndTime.ToString()) End If End Sub
Samples:
C#: AppointmentForm_DateTime_CS
VB: AppointmentForm_DateTime_VB
I hope you enjoyed learning about how to get the proper datetime while opening the appointment form in WorkWeek view in WinForms ScheduleControl.
You can refer to our WinForms Schedule Control’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Schedule Control documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms Schedule Control and other WinForms components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portalv. We are always happy to assist you!
WinForms Schedule Control