Back to Devexpress

How to: Create an Appointment for the Currently Selected Time Interval and Resource

windowsforms-2284-controls-and-libraries-scheduler-examples-selection-how-to-create-an-appointment-for-the-currently-selected-time-interval-and-resource.md

latest2.8 KB
Original Source

How to: Create an Appointment for the Currently Selected Time Interval and Resource

  • Nov 13, 2018
  • 2 minutes to read

This example creates a new appointment for the selected time interval and resource on a button click.

  1. Use the AppointmentDataStorage.CreateAppointment method to create a new appointment.
  2. Use the SchedulerControl.SelectedInterval property to get the selected time interval. Assign the interval’s start and end values to Appointment.Start and Appointment.End properties.
  3. Use the SchedulerControl.SelectedResource property to get the selected resource. Assign this value to the Appointment.ResourceId property.
  4. Add the appointment to the SchedulerStorage.Appointments collection.
csharp
void simpleButton1_Click(object sender, EventArgs e) {
  // Create a new appointment.
  Appointment apt = scheduler.DataStorage.CreateAppointment(AppointmentType.Normal);

  // Set the appointment's time interval to the selected time interval.
  apt.Start = scheduler.SelectedInterval.Start;
  apt.End = scheduler.SelectedInterval.End;

  // Set the appointment's resource to the resource that contains
  // the selected time interval.
  apt.ResourceId = scheduler.SelectedResource.Id;

  // Add the appointment to the appointment collection.
  scheduler.DataStorage.Appointments.Add(apt);
}
vb
' Create a new appointment.
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
  ' Create a new appointment.
  Dim apt As Appointment = scheduler.DataStorage.CreateAppointment(AppointmentType.Normal)

  ' Set the appointment's time interval to the selected time interval.
  apt.Start = scheduler.SelectedInterval.Start
  apt.End = scheduler.SelectedInterval.End

  ' Set the appointment's resource to the resource that contains
  ' the selected time interval.
  apt.ResourceId = scheduler.SelectedResource.Id

  ' Add the appointment to the appointment collection.
  scheduler.DataStorage.Appointments.Add(apt)
End Sub