)
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 add the appointments using custom appointment form in WinForms ScheduleControl?

Platform: WinForms |
Control: ScheduleControl |
Published Date: September 25, 2016 |
Last Revised Date: January 9, 2020
Tags: appointment

Custom appointment form

The custom appointment form can be shown by using the ShowingAppointmentForm event. The default appointment form can be canceled by using the e.Cancel property and custom appointment can be shown by calling its ShowDialog method.

C#

AppointmentForm form;
//Hook the event for showing the appointment form.
this.scheduleControl1.ShowingAppointmentForm += scheduleControl1_ShowingAppointmentForm;
/// <summary>
/// Raise the event when showing the appointment form
/// </summary>
void scheduleControl1_ShowingAppointmentForm(object sender, ShowingAppointFormEventArgs e)
{
   //Cancel the default appointment form for schedule control.
    e.Cancel = true;
    //Shows the Custom appointment form.
    form.ShowDialog();
}

VB

Private form As AppointmentForm
'Hook the event for showing the appointment.
Private Me.scheduleControl1.ShowingAppointmentForm += AddressOf scheduleControl1_ShowingAppointmentForm
''' <summary>
''' Raise the event when showing the appointment form
''' </summary>
Private Sub scheduleControl1_ShowingAppointmentForm(ByVal sender As Object, ByVal e As ShowingAppointFormEventArgs)
    'Cancel the default appointment form for schedule control.
    e.Cancel = True
    ' Shows the Custom appointment form.
    form.ShowDialog()
End Sub

 

Note:

The appointment can be added to the schedule control from custom appointment form.

C#

void ok_Click(object sender, System.EventArgs e)
{
    //Create a new schedule appointment
    IScheduleAppointment item = provider.NewScheduleAppointment();
    if (item != null)
    {
        item.AllDay = true;
        item.StartTime = this.StartDateDateTimePickerAdv.Value;
        item.EndTime = this.EndDateDateTimePickerAdv.Value;
        item.Subject = this.SubjectTextBoxExt.Text;
        item.LabelValue = this.comboBox1.SelectedIndex;
        //Appointment can be added in ScheduleDataProvider
        provider.AddItem(item);
    }
    this.schedulegrid.DataSource = provider;
    this.schedulegrid.GetScheduleHost().SetDataToDayPanels();
    this.Close();
}

VB

Private Sub ok_Click(ByVal sender As Object, ByVal e As System.EventArgs)
      'Create a new schedule appointment
      Dim item As IScheduleAppointment = provider.NewScheduleAppointment()
      If item IsNot Nothing Then
            item.AllDay = True
            item.StartTime = Me.StartDateDateTimePickerAdv.Value
            item.EndTime = Me.EndDateDateTimePickerAdv.Value
            item.Subject = Me.SubjectTextBoxExt.Text
            item.LabelValue = Me.comboBox1.SelectedIndex
            'Appointment can be added in ScheduleDataProvider
            provider.AddItem(item)
      End If
      Me.schedulegrid.DataSource = provider
      Me.schedulegrid.GetScheduleHost().SetDataToDayPanels()
      Me.Close()
End Sub

Screenshot

Show the custom appointment form

Samples:

C#: Custom AppointmentForm

VB: Custom AppointmentForm

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment
Comments
Felix Bagur
Nov 29, 2016
Thanks for this example. If you could please tell me how to add and retrieve a custom field in the form would be great.
When displaying the form I have the object ShowingAppointFormEventArgs with the item but I don't know how to add new fields.

In form.cs:
void scheduleControl1_ShowingAppointmentForm(object sender, ShowingAppointFormEventArgs e)
        {
            //Cancel the default appointform for schedule control
            e.Cancel = true;
            //Shows the Custom appointment form
  
            form.appointEvent = e;
            form.ShowDialog();

       }

In AppointmentForm.cs

  void AppointmentForm_Load(object sender, System.EventArgs e)
        {
            colorOptions = new List();
            colorOptions.Add("None");
            colorOptions.Add("Important");
            colorOptions.Add("Business");
            colorOptions.Add("Personal");
            colorOptions.Add("Vacation");
            colorOptions.Add("Must Attend");
            colorOptions.Add("Travel Required");
            colorOptions.Add("Needs Preparation");
            colorOptions.Add("Birthday");
            colorOptions.Add("Anniversary");
            colorOptions.Add("Phone Call");
            this.comboBox1.DataSource = colorOptions;
            this.comboBox1.SelectedIndex = this.appointEvent.Item.LabelValue ;

           

            if (this.appointEvent.Item.UniqueID != -1)
            {
                //Should I retrive here my custom fields?
            }

            this.StartDateDateTimePickerAdv.Value = this.appointEvent.Item.StartTime;
            this.EndDateDateTimePickerAdv.Value = this.appointEvent.Item.EndTime;
            this.SubjectTextBoxExt.Text = this.appointEvent.Item.Subject;
        }

Reply
Amal Raj Umapathy Selvam [Syncfusion]
Dec 01, 2016

Hi Felix,

 

Thanks for using Syncfusion products.

 

You can add or retrieve a custom field by accessing the specific controls in a form or specifying the item value for the appointment form throw the ShowingAppointFormEventArgs.Item. Please make use of the below code,

 

Code Example

void AppointmentForm_Load(object sender, System.EventArgs e)

{

    colorOptions = new List<string>();

    colorOptions.Add("None");

    colorOptions.Add("Important");

    colorOptions.Add("Business");

    colorOptions.Add("Personal");

    colorOptions.Add("Vacation");

    colorOptions.Add("Must Attend");

    colorOptions.Add("Travel Required");

    colorOptions.Add("Needs Preparation");

    colorOptions.Add("Birthday");

    colorOptions.Add("Anniversary");

    colorOptions.Add("Phone Call");

    this.comboBox1.DataSource = colorOptions;

 

    if (this.AppointmentEvents.Item.UniqueID != -1)

    {

        this.comboBox1.SelectedIndex = this.AppointmentEvents.Item.LabelValue;

        this.SubjectTextBoxExt.Text = this.AppointmentEvents.Item.Subject;

        this.StartDateDateTimePickerAdv.Value = this.AppointmentEvents.Item.StartTime;

        this.EndDateDateTimePickerAdv.Value = this.AppointmentEvents.Item.EndTime;

        this.StartTimeDateTimePickerAdv.Value = this.AppointmentEvents.Item.StartTime;

        this.EndTimeDateTimePickerAdv.Value = this.AppointmentEvents.Item.EndTime;

    }

    else

    {

        this.comboBox1.SelectedIndex = 0;

        this.SubjectTextBoxExt.Text = "New subject";

        this.StartDateDateTimePickerAdv.Value = this.AppointmentEvents.Item.StartTime;

        this.EndDateDateTimePickerAdv.Value = this.AppointmentEvents.Item.EndTime;

        this.StartTimeDateTimePickerAdv.Value = this.AppointmentEvents.Item.StartTime;

        this.EndTimeDateTimePickerAdv.Value = this.AppointmentEvents.Item.EndTime;

    }

}

 

The above code sets the new subject if the appointment is not set and if the appointment is set, then it will be retrieved.

 

If the above solution doesn’t meet your scenario, please create a new support incident using your Direct-Trac login,

 

https://www.syncfusion.com/account/login

 

Regards,

Amal Raj U.

Reply
Felix Bagur
Dec 01, 2016
Thank you very much for answering

Your answer is correct, but if I need to add a new field that is not in this.AppointmentEvents.Item I don't know how to proceed. For example if I want to have a custom form with a field for the department.

Thanks in advance,
Reply
Felix Bagur
Dec 01, 2016
I have found a solution,  create a class My_CustomAppointment that inherits from ScheduleAppointment where I add the new properties for the appointment.

Then in :
  - In the SimpleScheduleDataProvider class
Public Overrides Function NewScheduleAppointment () AscheduleAppointment
         Return New My_CustomAppointment ()
End Function

- In the AppointmentForm Class
Private Sub AppointmentForm_Load (ByVal sender As Object, ByVal and As
System.EventArgs) Handles MyBase.Load
...

Dim appAs Cls_My_CustomAppointment = CType (Me.appointEvent.Item, My_CustomAppointment)

Me.DeparmentTextBoxExt.Text = app.department

...

End Sub
Reply

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