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
3: public AppointmentWithEmail()
4: : base()
8: private string email = string.Empty;
10: public string Email
14: return this.email;
18: if (this.email != value)
20: this.email = value;
3. Next you will have to implement a very simple appointment factory:
1: public class CustomAppointmentFactory : IAppointmentFactory
3: #region IAppointmentFactory Members
5: public IEvent CreateNewAppointment()
7: return new AppointmentWithEmail();
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
3: public CustomAppointmentEditForm()
8: protected override void LoadSettingsFromEvent(Telerik.WinControls.UI.IEvent ev)
12: AppointmentWithEmail appointmentWithEmail = ev as AppointmentWithEmail;
13: if(appointmentWithEmail != null)
15: this.txtEmail.Text = appointmentWithEmail.Email;
19: protected override void ApplySettingsToEvent(Telerik.WinControls.UI.IEvent ev)
21: AppointmentWithEmail appointmentWithEmail = ev as AppointmentWithEmail;
22: if (appointmentWithEmail != null)
24: appointmentWithEmail.Email = this.txtEmail.Text;
29: protected override Telerik.WinControls.UI.IEvent CreateNewEvent()
31: return new AppointmentWithEmail();
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):
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)
5: this.radSchedulerDemo.AppointmentFactory = new CustomAppointmentFactory();
6: this.radSchedulerDemo.AppointmentEditDialogShowing += new EventHandler<AppointmentEditDialogShowingEventArgs>(radSchedulerDemo_AppointmentEditDialogShowing);
9: private IEditAppointmentDialog appointmentDialog = null;
11: void radSchedulerDemo_AppointmentEditDialogShowing(object sender, AppointmentEditDialogShowingEventArgs e)
13: if(this.appointmentDialog == null)
15: this.appointmentDialog = new CustomAppointmentEditForm();
17: e.AppointmentEditDialog = this.appointmentDialog;
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;
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!