We just finished working on the Q2 2009 release of RadControls for WinForms. One of the best things about releases is that we get to show off the cool new stuff that we managed to get done.

One of my favorite features is the full support for binding to custom fields in RadScheduler. Yes, this means that you finally can have RadScheduler bound to that email field in your data source.

And do you know what’s the best part? It’s fairly easy:

1. If you have not already done this, add your custom field to your data source.

2. You will need a custom appointment class that can store this additional data, the easiest way to do that is to inherit from the Appointment class that RadScheduler uses by default:

   1: public class AppointmentWithEmail : Appointment
   2: {
   3: public AppointmentWithEmail()
   4:         : base()
   5:     {
   6:     }
   7:  
   8: private string email = string.Empty;
   9:  
  10: public string Email
  11:     {
  12:         get
  13:         {
  14: return this.email;
  15:         }
  16:         set
  17:         {
  18: if (this.email != value)
  19:             {
  20: this.email = value;
  21: this.OnPropertyChanged("Email");
  22:             }
  23:         }
  24:     }
  25: }

3. Next you will have to implement a very simple appointment factory:

   1: public class CustomAppointmentFactory : IAppointmentFactory
   2: {
   3: #region IAppointmentFactory Members
   4:  
   5: public IEvent CreateNewAppointment()
   6:     {
   7: return new AppointmentWithEmail();
   8:     }
   9:  
  10: #endregion
  11: }

3. You will also need to inherit from the default appointment dialog and add some input controls and logic for your custom field:

   1: public partial class CustomAppointmentEditForm : Telerik.WinControls.UI.Scheduler.Dialogs.EditAppointmentDialog
   2: {
   3: public CustomAppointmentEditForm()
   4:     {
   5:         InitializeComponent();
   6:     }
   7:  
   8: protected override void LoadSettingsFromEvent(Telerik.WinControls.UI.IEvent ev)
   9:     {
  10: base.LoadSettingsFromEvent(ev);
  11: 
  12:         AppointmentWithEmail appointmentWithEmail = ev as AppointmentWithEmail;
  13: if(appointmentWithEmail != null)
  14:         {
  15: this.txtEmail.Text = appointmentWithEmail.Email;
  16:         }
  17:     }
  18:  
  19: protected override void ApplySettingsToEvent(Telerik.WinControls.UI.IEvent ev)
  20:     {
  21:         AppointmentWithEmail appointmentWithEmail = ev as AppointmentWithEmail;
  22: if (appointmentWithEmail != null)
  23:         {
  24:             appointmentWithEmail.Email = this.txtEmail.Text;
  25:         }
  26: base.ApplySettingsToEvent(ev);
  27:     }
  28:  
  29: protected override Telerik.WinControls.UI.IEvent CreateNewEvent()
  30:     {
  31: return new AppointmentWithEmail();
  32:     }
  33: }

The easiest way to do this is to create an inherited form with Visual Studio, then open it in the designer and add your custom UI. The extended form from the example looks like that (notice the Email field):

AppointmentFormWithEmail

4. Of course you will need to handle the AppointmentEditDialogShowing event of RadScheduler in order replace the default appointment dialog with your one. You will also have to give an instance of your appointment factory to RadScheduler so it can create instances of your custom appointment class:

   1: protected override void OnLoad(EventArgs e)
   2: {
   3: base.OnLoad(e);
   4:  
   5: this.radSchedulerDemo.AppointmentFactory = new CustomAppointmentFactory();
   6: this.radSchedulerDemo.AppointmentEditDialogShowing += new EventHandler<AppointmentEditDialogShowingEventArgs>(radSchedulerDemo_AppointmentEditDialogShowing);
   7: }
   8:  
   9: private IEditAppointmentDialog appointmentDialog = null;
  10:  
  11: void radSchedulerDemo_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
  12: {
  13: if(this.appointmentDialog == null)
  14:     {
  15: this.appointmentDialog = new CustomAppointmentEditForm();
  16:     }
  17:     e.AppointmentEditDialog = this.appointmentDialog;
  18: }

5. And finally you can add a mapping for your custom field to appointment mapping info. Note that the same appointment factory instance is assigned to the event provider.

   1: SchedulerBindingDataSource dataSource = new SchedulerBindingDataSource();
   2: dataSource.EventProvider.AppointmentFactory = this.radSchedulerDemo.AppointmentFactory;
   3:  
   4: AppointmentMappingInfo appointmentMappingInfo = new AppointmentMappingInfo();
   5: appointmentMappingInfo.Mappings.Add(new SchedulerMapping("Email", "Email"));

I will not attach the code here, because you can find it in the updated data binding example for RadScheduler.

Don’t forget to download the Q2 2009 release and play with the new features!


Comments

Comments are disabled in preview mode.