Skip to main content

Collection of Custom Objects

  • 3 minutes to read

Note

You are viewing documentation for the legacy WPF Scheduler control. If you’re starting a new project, we strongly recommend that you use a new control declared in the DevExpress.Xpf.Scheduling namespace. If you decide to upgrade an existing project in order to switch to the updated scheduler control, see the Migration Guidelines document.

The Scheduler can be bound to a collection of custom objects. This document contains a brief overview of collection types, and contains an example of code that is used to implement appointment and resource objects.

A Scheduler Storage can be bound to a System.ComponentModel.BindingList<T> class instance (a generic collection that supports data binding), or a System.Collections.ObjectModel.ObservableCollection<T> class instance (a dynamic data collection that provides notifications). When you consider the type of an item in a collection, make sure that its properties can be mapped to Scheduler Storage fields in a straightforward way (i.e., the property value type must correspond to the data type used in the mapping). This rule prohibits the use of the System.Collections.ObjectModel.ObservableCollection<DevExpress.XtraScheduler.IAppointment> collection as the data source because the AppointmentMappingInfo.RecurrenceInfo mapping requires a mapped field of the string type, not the RecurrenceInfo data type. Review the code snippet below for information on the data types required for specific mappings.

For an example of the Scheduler bound to an observable collection, review the Observable Collection document.

The following code demonstrates how to implement a custom appointment and resource objects.

using System;
using System.Collections.Generic;
using System.ComponentModel;
    partial class MainViewModel {
        public BindingList<Doctor> Doctors { get; set; }
        public BindingList<HospitalAppointment> Appointments { get; set; }
        public MainViewModel() {
            Doctors = new BindingList<Doctor>();
            Appointments = new BindingList<HospitalAppointment>();
            FillEmployees();
            FillTasks();
        }

        public class Doctor {
            public object Id { get; set; }
            public string Name { get; set; }
        }

        public class HospitalAppointment {
            public string PatientName { get; set; }
            public string Location { get; set; }
            public DateTime StartTime { get; set; }
            public DateTime EndTime { get; set; }
            public string InsuranceNumber { get; set; }
            public bool FirstVisit { get; set; }
            public object DoctorId { get; set; }
            public string Notes { get; set; }
        }
    }