PersistentObject.Id Property

Gets a persistent object identifier previously retrieved from an external database or set at runtime.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v20.2.Core.dll


public virtual object Id { get; }

Property Value

Type Description

An object that is the identifier.


Appointment ID in WinForms Scheduler

For the WinForms Scheduler, the appointment identifier is not mapped, by default. In this situation, the Id property will always return null. This does not indicate any problem because an appointment object uses internal methods to retrieve its unique identifier from the data source. However, to get the correct value of the Id property, you can map the appointment identifier field using the AppointmentMappingInfo.AppointmentId property or Appointment Mappings Wizard. Usually, you map an appointment id to meet the requirements of the Gantt View, so the Wizard has a "Gantt view mappings" check box. You have to select it to specify this mapping.

When appointment ID mapping is specified, the scheduler will try to save the appointment identifier back to the data store. You can change this behavior using the AppointmentStorage.CommitIdToDataSource property. If an appointment identifier is generated by the data source, set the CommitIdToDataSource property to false.

If the appointment identifier is provided by the data source (e.g., an autoincremented field), modify the application code as described below:

This example demonstrates the WinForms Scheduler control bound to a Microsoft SQL CE database.

using DevExpress.XtraScheduler;
using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Windows.Forms;

namespace Scheduler_SQLCE_Example {
    public partial class Form1 : Form {
        public Form1() {
            this.schedulerStorage1.Appointments.ResourceSharing = true;

            //this.schedulerStorage1.Appointments.CommitIdToDataSource = false;
            this.schedulerStorage1.AppointmentsInserted += schedulerStorage1_AppointmentsInserted;
            appointmentsTableAdapter.Adapter.RowUpdated += new SqlCeRowUpdatedEventHandler(appointmentsTableAdapter_RowUpdated);
        private void appointmentsTableAdapter_RowUpdated(object sender, SqlCeRowUpdatedEventArgs e) {
            // Gets ID for a new appointment from the SQL CE data source
            if (e.Status == UpdateStatus.Continue && e.StatementType == StatementType.Insert) {
                int id = 0;
                using (SqlCeCommand cmd = new SqlCeCommand("SELECT @@IDENTITY",
                    appointmentsTableAdapter.Connection)) {
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                e.Row["UniqueID"] = id;

        private void Form1_Load(object sender, EventArgs e) {
            // TODO: This line of code loads data into the 'dXDBDataSet2.Resources' table. You can move, or remove it, as needed.
            // TODO: This line of code loads data into the 'dXDBDataSet2.Appointments' table. You can move, or remove it, as needed.

        private void schedulerStorage1_AppointmentChanging(object sender, DevExpress.XtraScheduler.PersistentObjectCancelEventArgs e) {
            string apt_id = string.Empty;
            if (((Appointment)e.Object).Id == null)
                apt_id = "null";
                apt_id = ((Appointment)e.Object).Id.ToString();
            MessageBox.Show("AppointmentChanging event for " + apt_id);

        private void OnApptChangedInsertedDeleted(object sender, PersistentObjectsEventArgs e) {

        void schedulerStorage1_AppointmentsInserted(object sender, PersistentObjectsEventArgs e) {
            // Synchronize appointment IDs in the storage with the SQL CE data source
            AppointmentBaseCollection apts = e.Objects as AppointmentBaseCollection;
            foreach (Appointment apt in apts)
                DataRowView dataRow = apt.GetSourceObject(this.schedulerStorage1) as DataRowView;
                this.schedulerStorage1.SetAppointmentId(apt, dataRow.Row["UniqueID"]);

        void UpdateSource() {


If an appointment identifier is generated by the application, modify the application code as described below:

Appointment ID in ASPxScheduler

For the ASP.NET Scheduler, the appointment identifier should be mapped to the corresponding identity field of the data source using the using the ASPxAppointmentMappingInfo.AppointmentId property. To set the identifier for the newly created appointment, you can use the ASPxSchedulerStorage.SetAppointmentId method and technique described in the How to: Bind an ASPxScheduler to MS SQL Server Database (Step-by-Step Guide) document.

However, you can use the ASPxAppointmentStorage.AutoRetrieveId property instead of manually retrieving and setting the appointment identifier. Set the AutoRetrieveId value to true and all the necessary operations will be accomplished automatically, as long as the bound data source is one of the following controls: the SqlDataSource, the AccessDataSource or the ObjectDataSource.

The Appointment Mappings Wizard allows you to select the check box labeled "Retrieve and update ID automatically". This action sets the AutoRetrieveId property at design time.


See Also