Edit this page

Scheduler Mapping

The SchedulerMapping class is responsible for mapping a single property from the data source to a scheduler property, which allows you to specify convert callback methods in order to convert values to and from the data source if needed.


To associate a field with a different type than the scheduler type, for example, a background id that is written as a string in the database:

1. Create two methods with the following signatures:

object ConvertBackgrounIdToScheduler(object obj)
    if (!(obj is DBNull))
        string appointmentBackground = (string)obj;
        switch (appointmentBackground)
            case "Business":
                return AppointmentBackground.Business;
            case "Important":
                return AppointmentBackground.Important;
            case "MustAttend":
                return AppointmentBackground.MustAttend;
            case "PhoneCall":
                return AppointmentBackground.PhoneCall;
            //TO DO other backgrounds
    return AppointmentBackground.None;
object ConvertBackgrounIdToDataSource(object obj)
    AppointmentBackground appointmentBackground = (AppointmentBackground)obj;
    switch (appointmentBackground)
        case AppointmentBackground.Business:
            return "Business";
        case AppointmentBackground.Important:
            return "Important";
        case AppointmentBackground.MustAttend:
            return "MustAttend";
        case AppointmentBackground.PhoneCall:
            return "PhoneCall";
        //TO DO other backgrounds
    return "None";

Private Function ConvertBackgrounIdToScheduler(ByVal obj As Object) As Object
    If Not (TypeOf obj Is DBNull) Then
        Dim appointmentBackground As String = CStr(obj)
        Select Case appointmentBackground
            Case "Business"
                Return Telerik.WinControls.UI.AppointmentBackground.Business
            Case "Important"
                Return Telerik.WinControls.UI.AppointmentBackground.Important
            Case "MustAttend"
                Return Telerik.WinControls.UI.AppointmentBackground.MustAttend
            Case "PhoneCall"
                Return Telerik.WinControls.UI.AppointmentBackground.PhoneCall
                'TO DO other backgrounds
        End Select
    End If
    Return AppointmentBackground.None
End Function
Private Function ConvertBackgrounIdToDataSource(ByVal obj As Object) As Object
    Dim appointmentBackground As AppointmentBackground = CType(obj, AppointmentBackground)
    Select Case appointmentBackground
        Case appointmentBackground.Business
            Return "Business"
        Case appointmentBackground.Important
            Return "Important"
        Case appointmentBackground.MustAttend
            Return "MustAttend"
        Case appointmentBackground.PhoneCall
            Return "PhoneCall"
            'TO DO other backgrounds
    End Select
    Return "None"
End Function

2. Apply settings of the BackgroundId mapping in the AppointmentMappingInfo:

SchedulerMapping backgroundIdSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("BackgroundId");
backgroundIdSchedulerMapping.ConvertToScheduler = new ConvertCallback(this.ConvertBackgrounIdToScheduler);
backgroundIdSchedulerMapping.ConvertToDataSource = new ConvertCallback(this.ConvertBackgrounIdToDataSource);

Dim backgroundIdSchedulerMapping As SchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("BackgroundId")
backgroundIdSchedulerMapping.ConvertToScheduler = New ConvertCallback(AddressOf Me.ConvertBackgrounIdToScheduler)
backgroundIdSchedulerMapping.ConvertToDataSource = New ConvertCallback(AddressOf Me.ConvertBackgrounIdToDataSource)

Null Fields in the Data Base

If the database has fields that can be Null then you need to add converters for those fields. For example, let's suppose that the database has a field "Location", which is a string and you wish to check whether its value is DBNull. If it is DBNull you would want to convert it to null. Here are the steps:

1. Create a conversion method with the following signature:

object ConvertLocationToScheduler(object obj)
    if (obj is DBNull)
        return null;
    return obj;

Private Function ConvertLocationToScheduler(ByVal obj As Object) As Object
    If TypeOf obj Is DBNull Then
        Return Nothing
    End If
    Return obj
End Function

2. Apply the Location mapping settings in the AppointmentMappingInfo:

AppointmentMappingInfo appointmentMappingInfo = new AppointmentMappingInfo();
appointmentMappingInfo.Location = "Location";
SchedulerMapping locationSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("Location");
locationSchedulerMapping.ConvertToScheduler = new ConvertCallback(this.ConvertLocationToScheduler);

Dim appointmentMappingInfo As New AppointmentMappingInfo()
appointmentMappingInfo.Location = "Location"
Dim locationSchedulerMapping As SchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("Location")
locationSchedulerMapping.ConvertToScheduler = New ConvertCallback(AddressOf Me.ConvertLocationToScheduler)

Not Read-Only Id Field Other than Guid

If the Id field type is different than a Guid, and/or it is not read only in the data table, then you will need to add a converter to convert the type to a Guid. This case holds true for Resources and Appointments.

If Id is read only in the data set, then the Scheduler will rely on the way the data set handles read only Id's.

1. Create a methods with the following signatures

object ConvertUniqueIdToScheduler(object obj)
    return new EventId(obj);
object ConvertUniqueIdToDataSource(object obj)
    EventId eventId = obj as EventId;
    //if the appointment is added from the scheduler the eventId.KeyValue is Guid
    if (eventId.KeyValue is Guid)
        //return the value that is in your object/dataset
    //if the appointment is loaded from an object/dataset the eventId.KeyValue is its representation in the object/datase
    return eventId.KeyValue;

Private Function ConvertUniqueIdToScheduler(ByVal obj As Object) As Object
    Return New EventId(obj)
End Function
Private Function ConvertUniqueIdToDataSource(ByVal obj As Object) As Object
    Dim eventId As EventId = TryCast(obj, EventId)
    'if the appointment is added from the scheduler the eventId.KeyValue is Guid
    If TypeOf eventId.KeyValue Is Guid Then
        'return the value that is in your object/dataset
    End If
    'if the appointment is loaded from an object/dataset the eventId.KeyValue is its representation in the object/datase
    Return eventId.KeyValue
End Function

2. Apply the settings of the UniqueId mapping in the AppointmentMappingInfo:

SchedulerMapping uniqueIdSchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("UniqueId");
uniqueIdSchedulerMapping.ConvertToScheduler = new ConvertCallback(this.ConvertUniqueIdToScheduler);
uniqueIdSchedulerMapping.ConvertToDataSource = new ConvertCallback(this.ConvertUniqueIdToDataSource);

Dim uniqueIdSchedulerMapping As SchedulerMapping = appointmentMappingInfo.FindBySchedulerProperty("UniqueId")
uniqueIdSchedulerMapping.ConvertToScheduler = New ConvertCallback(AddressOf Me.ConvertUniqueIdToScheduler)
uniqueIdSchedulerMapping.ConvertToDataSource = New ConvertCallback(AddressOf Me.ConvertUniqueIdToDataSource)

ConvertValueToScheduler and ConvertValueToDataSource Events

Similar to the ConvertToScheduler and ConvertToDataSource callbacks of the SchedulerMapping, in R1 2018 we introduced the ConvertValueToScheduler and ConvertValueToDataSource events to handle the conversion from a value coming from the DataSource to the RadScheduler's respective type and vice versa.

Conversion Events

public void EventSubscriptions()
    AppointmentMappingInfo appointmentMapping = new AppointmentMappingInfo();
    //other code for the AppointmentMappingInfo setup
    appointmentMapping.FindBySchedulerProperty("ResourceId").ConvertValueToScheduler += ConvertValueToScheduler;
    appointmentMapping.FindBySchedulerProperty("ResourceId").ConvertValueToDataSource += ConvertValueToDataSource;
private void ConvertValueToDataSource(object sender, ConvertFromToSchedulerEventArgs e)
    if (e.PropertyName == "ResourceId")
        e.Value = (int)((EventId)e.Value).KeyValue;
private void ConvertValueToScheduler(object sender, ConvertFromToSchedulerEventArgs e)
    if (e.PropertyName == "ResourceId")
        e.Value = new EventId((int)e.Value);

Public Sub EventSubscriptions()
    Dim appointmentMapping As AppointmentMappingInfo = New AppointmentMappingInfo
    'other code for the AppointmentMappingInfo setup
    AddHandler appointmentMapping.FindBySchedulerProperty("ResourceId").ConvertValueToScheduler, AddressOf ConvertValueToScheduler
    AddHandler appointmentMapping.FindBySchedulerProperty("ResourceId").ConvertValueToDataSource, AddressOf ConvertValueToDataSource
End Sub
Private Sub ConvertValueToDataSource(ByVal sender As Object, ByVal e As ConvertFromToSchedulerEventArgs)
    If (e.PropertyName = "ResourceId") Then
        e.Value = CType(CType(e.Value, EventId).KeyValue, Integer)
    End If
End Sub
Private Sub ConvertValueToScheduler(ByVal sender As Object, ByVal e As ConvertFromToSchedulerEventArgs)
    If (e.PropertyName = "ResourceId") Then
        e.Value = New EventId(CType(e.Value, Integer))
    End If
End Sub

See Also

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article