RadControls for WinForms

RELATED VIDEOS

Adding Custom Fields to RadScheduler Appointmentss

In this video, you will learn how to add custom fields to the RadScheduler for WinForms. You'll learn how to create the required classes, mappings, and dialogs that make it easy to integrate any custom data in a Scheduler appointment. (Runtime: 19:48)

scheduler-data-binding-codeless-data-binding 001
Introduction to RadScheduler for WinForms

In this webinar, Telerik Developer Support Specialist Robert Shoemate will introduce RadScheduler and demonstrate how to utilize its powerful feature set in your own applications. By attending this webinar, you will learn about features such as codeless data binding, adding custom fields, and UI customization. (Runtime: 55:58)

scheduler-data-binding-codeless-data-binding 002

RELATED BLOGS

Adding Custom Fields to RadScheduler Appointments When using RadScheduler for WinForms, it will almost always need to be customized in some way. This could come in the form of custom dialogs, context menus, or even custom appointments. In this blog entry, I am going to explain the steps required to add a custom field to RadScheduler. Read full post ...

    

scheduler-appointments-and-dialogs-adding-a-custom-field-to-the-editappointment-dialog 001

The following tutorial will demonstrate how you can customize the default EditAppointmentDialog (shown above) by adding a custom field to it. In our case, we are going to add an E-mail field. This field will not only exist in the dialog as a control, but will also be stored as a value in the custom appointment provided below.

  1. Subscribe to the AppointmentEditDialogShowing event.
  2. In the event handler use the AppointmentEditDialog property of the event arguments to set a new dialog.
    Copy[C#] Associating new EditAppointment dialog
    void radScheduler1_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
    {
        if (this.appointmentDialog == null)
        {
            this.appointmentDialog = new CustomAppointmentEditForm();
        }
       e.AppointmentEditDialog = this.appointmentDialog;
    }
    Copy[VB.NET] Associating new EditAppointment dialog
    Private Sub radScheduler1_AppointmentEditDialogShowing(ByVal sender As Object, ByVal e As AppointmentEditDialogShowingEventArgs)
        If Me.appointmentDialog Is Nothing Then
            Me.appointmentDialog = New CustomAppointmentEditForm()
        End If
        e.AppointmentEditDialog = Me.appointmentDialog
    End Sub

In the snippet we use an instance of CustomAppointmentEditForm which is a dialog that extends the default scheduler’s dialog. For example, you may need to add an e-mail field in the dialog. You can create such dialog by doing the following:

  1. Create a new appointment class which includes the E-mail property and derives from the Appointment class.
    Copy[C#] Extending the Appointment class
    public class AppointmentWithEmail : Appointment
    {
        public AppointmentWithEmail()
            : base()
        {
        }
        private string email = string.Empty;
        public string Email
        {
            get
            {
                return this.email;
            }
            set
            {
                if (this.email != value)
                {
                    this.email = value;
                    this.OnPropertyChanged("Email");
                }
            }
        }
    }
    Copy[VB.NET] Extending the Appointment class
    Public Class AppointmentWithEmail
        Inherits Appointment
        Public Sub New()
            MyBase.New()
        End Sub
    
        Private _email As String = String.Empty
        Public Property Email() As String
            Get
                Return Me._email
            End Get
            Set(ByVal value As String)
                If Me._email <> value Then
                    Me._email = value
                    Me.OnPropertyChanged("Email")
                End If
            End Set
        End Property
    End Class

  2. Create an appointment factory which uses our AppointmentWithEmail class.
    Copy[C#]
    public class CustomAppointmentFactory : IAppointmentFactory
    {
        #region IAppointmentFactory Members
        public IEvent CreateNewAppointment()
        {
            return new AppointmentWithEmail();
        }
        #endregion
    }
    Copy[VB.NET]
    Public Class CustomAppointmentFactory
        Implements IAppointmentFactory
    #Region "IAppointmentFactory Members"
        Public Function CreateNewAppointment() As IEvent Implements IAppointmentFactory.CreateNewAppointment
            Return New AppointmentWithEmail()
        End Function
    #End Region
    End Class
  3. Create a new dialog form which inherits from EditAppointmentDialog
    Copy[C#] Extending the EditAppointmentDialog
    public partial class CustomAppointmentEditForm : EditAppointmentDialog
    {
        public CustomAppointmentEditForm()
        {
            InitializeComponent();
        }
    
        protected override void LoadSettingsFromEvent(IEvent ev)
        {
            base.LoadSettingsFromEvent(ev);
    
            AppointmentWithEmail appointmentWithEmail = ev as AppointmentWithEmail;
            if (appointmentWithEmail != null)
            {
                this.txtEmail.Text = appointmentWithEmail.Email;
            }
        }
    
        protected override void ApplySettingsToEvent(IEvent ev)
        {
            AppointmentWithEmail appointmentWithEmail = ev as AppointmentWithEmail;
            if (appointmentWithEmail != null)
            {
                appointmentWithEmail.Email = this.txtEmail.Text;
            }
            base.ApplySettingsToEvent(ev);
        }
    
        protected override IEvent CreateNewEvent()
        {
            return new AppointmentWithEmail();
        }
    }
    Copy[VB.NET] Extending the EditAppointmentDialog
    Public Class CustomAppointmentEditForm
        Public Sub New()
            InitializeComponent()
        End Sub
    
        Protected Overrides Sub LoadSettingsFromEvent(ByVal ev As IEvent)
            MyBase.LoadSettingsFromEvent(ev)
    
            Dim appointmentWithEmail As AppointmentWithEmail = TryCast(ev, AppointmentWithEmail)
            If appointmentWithEmail IsNot Nothing Then
                Me.txtEmail.Text = appointmentWithEmail.Email
            End If
        End Sub
    
        Protected Overrides Sub ApplySettingsToEvent(ByVal ev As IEvent)
            Dim appointmentWithEmail As AppointmentWithEmail = TryCast(ev, AppointmentWithEmail)
            If appointmentWithEmail IsNot Nothing Then
                appointmentWithEmail.Email = Me.txtEmail.Text
            End If
            MyBase.ApplySettingsToEvent(ev)
        End Sub
    
        Protected Overrides Function CreateNewEvent() As IEvent
            Return New AppointmentWithEmail()
        End Function
    End Class
  4. Last, but not least we should assign the custom AppointmentFactory to our RadScheduler. This will come in handy when you create your appointments in-line:
    Copy[C#] Extending the EditAppointmentDialog
    this.radScheduler1.AppointmentFactory = new CustomAppointmentFactory();
    Copy[VB.NET] Extending the EditAppointmentDialog
    Me.RadScheduler1.AppointmentFactory = New CustomAppointmentFactory()

scheduler-appointments-and-dialogs-adding-a-custom-field-to-the-editappointment-dialog 002

 

Use the custom dialog in the AppointmentDialogShowing event handler.