Data Binding

Data Binding

Old forum URL:

demwa posted on Monday, December 03, 2007

I am developing an Human Resources and payroll system.I have created an employee object which can be of four types contract employee,Permanent employee,temporal employee and expariate.I want to be able to change an employee from one type to another type of employee.I have created a polymorphic child object called EmployeeType which can be of any of the types mentioned above.on the employees form  i have put a combobox which is bound to the employeetype namevalue list.When I select any options in the combobox a new  type of child if the employee type is differennt from the current employee type is created.However the the bound text boxes are not updated to reflect the initial values of the newly created child object of the employee.For example both the temporal employee and contract employee types have the startdate and enddate properties to reflect the start and expiry of the contracts/temporal assignement.When I change a temporal employee to contract employee the startdate and enddate continue to reflect the same startdate and enddate properties of the temporal employee and if save the objects to the database only the employeeid is inserted into the database,startdate and enddate are code snippets are show below .Can someone help me



mEmployee = Employee


Me.EmployeeBindingSource.DataSource = mEmployee

Me.EmployeeTypeListBindingSource.DataSource = Payroll.Library.EmployeeTypeList.GetList

Me.EmployeeListBindingSource.DataSource = Payroll.Library.EmployeeList.GetEmployeeList


With ComboBox1

.DataSource = Payroll.Library.EmployeeTypeList.GetList

.DisplayMember = "Name"

.ValueMember = "Value"

.DataBindings.Add("SelectedValue", mEmployee, "Type")

.DataBindings(0).DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged

End With

With Me.TextBox1

.DataBindings.Add("Text", mEmployee.EmployeeType, "StartDate")

End With

Employee Object

Private Sub SetEmployeeType(ByVal ID As Integer)

OldEmployeeType = mEmployeeType


mEmployeeType = EmployeeTypeFactory.NewEmployeeType(ID)

End Sub

Public Property Type() As String


Return mTypeList.Value(mType)

End Get

Set(ByVal value As String)

If mType <> mTypeList.Key(value) Then

mType = mTypeList.Key(value)



End If

End Set

End Property

Copyright (c) Marimer LLC