How to: Create an Appointment for the Currently Selected Time Interval and Resource
- 2 minutes to read
This example demonstrates how to create a new appointment for the time interval currently selected in the scheduler. The selected time interval is accessed via the SchedulerControl.SelectedInterval property, and the selected resource is accessed via the SchedulerControl.SelectedResource property. An appointment is added to the SchedulerStorage.Appointments collection of the scheduler’s SchedulerControl.Storage.
// Delete all appointments.
scheduler.Storage.Appointments.Clear();
// Select time interval
scheduler.ActiveView.SetSelection(new TimeInterval(DateTime.Now, new TimeSpan(2, 40, 0)), scheduler.ActiveView.GetResources()[1]);
// Group by resource.
scheduler.GroupType = SchedulerGroupType.Resource;
// Create a new appointment.
Appointment apt = scheduler.Storage.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 which contains
// the currently selected time interval.
apt.ResourceId = scheduler.SelectedResource.Id;
// Add the new appointment to the appointment collection.
scheduler.Storage.Appointments.Add(apt);