Following the initial load of data into bound controls as my form loads , I
want to detect when a user have changed the value of one of the Combo or
text box fields etc This will allow me to test the bDataChanged variable and
warn the user that data has changed if they attempt to close the screen
without saving.
The problem I have is that I can't reliably set bDataChanged to False
immediatly after the Initial load of the form as the DataChange event seems
to fire again when the Me.ShowDialog(frmOwner) is executed.
I'm doing my initial display and capturing the data change event with the
code given below:-
Suggestions as to what I'm doing wrong would be appreciated.
Thanks
Andy
Public Sub Display(ByVal frmOwner As Form, ByVal iVehicleId As Integer,
ByVal iGroupId As Integer, ByVal iCompanyId As Integer, ByVal iBranchId As
Integer, ByVal iCostCentreId As Integer)
Try
UnBindControls()
'Vehicle Details Objects
Dim _VehicleBLL As New AmcNet.BusinessLogic.Vehicle
_Vehicle = New AmcNet.Info.VehicleInfo 'new
_Vehicles = _VehicleBLL.GetVehicleById(iVehicleId)
_Vehicle = _Vehicles.GetValue(0)
LoadDropDowns()
BindFields(_Vehicle)
LoadVehicleListView(iNotificationGroup, iNotificationCompany,
iNotificationBranch, iNotificationCostCentre)
HighlightSelectedRecord(_Vehicle.Registration)
bDataChanged = False ' Reset As This will be True after initial
Data Load
Me.ShowDialog(frmOwner)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Private Sub DataChanged(ByVal sender As Object, ByVal e As System.EventArgs)
_
Handles txtRegistration.TextChanged, _
txtNotes.TextChanged, _
txtCCRating.TextChanged, _
txtCCRating.TextChanged, _
txtLeaseSupplier.TextChanged, _
txtModel.TextChanged, _
cboBodyType.ValueChanged, _
cboClass.ValueChanged, _
cboMake.ValueChanged, _
cboOwnership.ValueChanged, _
dtpStartDate.ValueChanged, _
dtpEndDate.ValueChanged
bDataChanged = True
End Sub