Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1225
An alternative (better) method of dealing with custom Appointment fields
posted

Being new the library I was disappointed to see the main recommendation for storing additional appointment data is to stuff the data into the tag.  While functional,  this is far from elegant and I would really like to see the ability to extend  the Appointment class via inheritance.

In the mean time I am using a different approach which does not use the tag and enables me to store and retrieve additional appointment data.  By sharing the BindingSource from the UltraCalendarInfo to my custom Appointment  form I am able to bind the controls so that they edit all the columns, both the standard ones like StartTime and EndTime as well as my custom fields.  My database contains only the columns I want and not the duplicated binary versions of the customer data in the tag/AllProperties field as has been suggested.

There are two scenarios to deal with Editing an existing appointment and adding a new one.  Both call the custom form but there are some differences in terms of getting the BindingSource positioned correctly.  On my custom appointment  form I created a constructor which takes a parameter of type BindingSource and pass the AppointmentBindingSource to the form:

Dim AppointmentDialog As myCustomAppointmentForm = New myCustomAppointmentForm(UltraCalendarInfo1.DataBindingsForAppointments.DataSource)

In the form load of the customer Appointment form, this binding source is used  to bind the all the controls and  edit all the columns including my customer fields.  For example:       

Me.SubjectTextBox.DataBindings.Add(New System.Windows.Forms.Binding("Text",_ AppointmentBindingSource, "Subject", True))

I handle the BindingComplete event to ensure the BindingSource remains synchronized between the two forms:

Private Sub AppointmentBindingSource_BindingComplete(   ByVal sender As Object,  _

                                                                                                              ByVal e As BindingCompleteEventArgs)  _

                                                                             Handles AppointmentBindingSource.BindingComplete

  If e.BindingCompleteContext  =  BindingCompleteContext.DataSourceUpdate _

    AndAlso e.Exception Is Nothing Then

       e.Binding.BindingManagerBase.EndCurrentEdit()

  End If

End Sub

Finally, right before calling the custom Appointment form in the BeforeDisplayAppointmentDialog event I force the Bindingsource to reposition to the appointment record being edited:

AppointmentBindingSource.Position = e.Appointment.BindingListIndex

To be able to deal with a new appointment, the appointment needs to be created and added to appointment needs to be created and added to the UltraCalendarInfo1.Appointments collection.  This will perform the BindingSource.addnew that we need.

If e.IsExistingAppointment Then

           Me.UltraCalendarInfo1.Appointments.Add(e.appointment) 

End If

On the return from the custom Appointment  form (which I call as a dialog)  if the user pressed Cancel then we need to get rid of the appointment we just added:

Dim dResult As DialogResult = AppointmentDialog.ShowDialog()

         If dResult = DialogResult.OK Then

            AppointmentTableAdapter.Update(Me.HousecallDataSet.appointment)

        Else

            AppointmentBindingSource.CancelEdit()

            Me.UltraCalendarInfo1.Appointments.Remove(appt)

        End If

 

 

Parents
No Data
Reply Children