Skip to main content
A newer version of this page is available. .

Data Binding

  • 3 minutes to read

Most DevExpress data-aware controls are compatible with any data access technology (ADO.NET, Entity Framework, XPO, etc.) and capable to display data from any data source that implements the IList, IBindingList, or ITypedList interface. Refer to these help topics for more details: Traditional Data Binding Methods and Data Binding Common Concepts.

You can retrieve Scheduler appointments (including their reminders, statuses and labels) and resources from data sources. The Scheduler uses the SchedulerDataStorage component to load data. Use the smart tag menu to assign sources.

storage-tag

Mappings

Appointments, resources, labels, and other elements have required and optional data-bound properties. For instance, appointment start and end dates, ID, and type are required properties, whereas time zone ID, status, subject, reminder, etc. are optional. The Mappings section enumerates all bindable properties and explains which are required.

Use the Mappings Wizard to set up mappings at design time.

map-wizard

You can also set object mappings in code.

private void MapAppointmentData()
{
    //required mappings
    schedulerDataStorage1.Appointments.Mappings.End = "EndDate";
    schedulerDataStorage1.Appointments.Mappings.Start = "StartDate";
    //optional mappings
    schedulerDataStorage1.Appointments.Mappings.AllDay = "AllDay";
    //. . .
    schedulerDataStorage1.Appointments.Mappings.ResourceId = "ResourceIDs";
    //custom fields
    schedulerDataStorage1.Appointments.CustomFieldMappings.Add(
        new AppointmentCustomFieldMapping("MyNote", "CustomField1")); 
}

Import Holidays from a Data Source

To import holidays, parse loaded data and populate the WorkDaysCollection with Holiday objects. See the “Holidays” Demo module for an example.

Note

Holiday cells have a different appearance than regular day cells but do not impose any user restrictions. If you want to block specific dates, create all-day TimeRegion objects.

Sample Data Sources

If you do not have a ready-to-use data source populated with data, you can generate a new source. Documents in the Data Sources section contain sample data sources of different types (SQL Server, Entity Framework, XML, etc.) you can use as references.

Unbound mode

Whether your Scheduler is bound to a data source or not, you can add new elements (appointments, resources, etc.) directly from code. To do that, call the SchedulerDataStorage‘s Create… methods.

The code below adds a new status, a new label, and a new appointment that has this new status and label. The appointment lasts for 15 minutes, repeats five times, and occurs on every second day. Note that “Create…” methods initialize new objects, but do not add them to a storage; this is why you have to additionally call the Add method.

Appointment apt = schedulerDataStorage1.CreateAppointment(
    AppointmentType.Pattern,
    DateTime.Now,
    DateTime.Now.AddMinutes(15),
    "Appointment Created in Code");
apt.Location = "My Location";
apt.Description = "My Description";
apt.RecurrenceInfo.Type = RecurrenceType.Daily;
apt.RecurrenceInfo.Periodicity = 2;
apt.RecurrenceInfo.Start = apt.Start;
apt.RecurrenceInfo.Range = RecurrenceRange.OccurrenceCount;
apt.RecurrenceInfo.OccurrenceCount = 5;
schedulerDataStorage1.Appointments.Add(apt);

var lbl = schedulerDataStorage1.Appointments.Labels.CreateNewLabel("vi","Very Important");
lbl.SetColor(Color.IndianRed);
schedulerDataStorage1.Appointments.Labels.Add(lbl);

var status = schedulerDataStorage1.Appointments.Statuses.CreateNewStatus("vb", "Very Busy");
status.SetBrush(new HatchBrush(HatchStyle.ForwardDiagonal, Color.IndianRed, Color.White));
schedulerDataStorage1.Appointments.Statuses.Add(status);

apt.StatusKey = "vb";
apt.LabelKey = "vi";