)
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 get the proper datetime while opening the appointment form in WorkWeek view in WinForms ScheduleControl?

Platform: WinForms |
Control: ScheduleControl |
Published Date: June 8, 2017 |
Last Revised Date: January 9, 2020
Tags: appointments

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, 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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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