Need to check if dataset has changes before closing a form

Canopy High

Active member
Joined
Aug 29, 2007
Messages
35
Location
Dasmarinas
Programming Experience
Beginner
Hi,

I have a form that shows the row values of a table and this values are all binded to the appropriate textboxes.

Now I am trying to check if the dataset has changes before the form unloads. If the ds.HasChanges is called inside a button that closes the form it works. But when I tried to put it inside the form_closing event it doesn't detect the changes and I am clueless.:confused:

Any response would be very much appreciated.

Thanks.
 
Still Doesn't work

Hi there,

The code in the thread that you sent me still does not work.

I dont know what is wrong man, If I close the form using a button, it detects the changes, but the (x) button does not. ???

Any help would be very much appreciated.
 
Sorry.. Got It Already..

I already got it man!!!

Sorry for the query. :)

Thanks for the idea.

Jah Bless!!! :D
 
Here is my code by the way. Hope this will give an idea to those who will view this thread. This is placed inside the Form_Closing event.

VB.NET:
Me.Validate()
Me.dsDtlBS.EndEdit() ' BindingSource
If Not Me.dsDtl.HasChanges Then Return

Dim msgResult As MsgBoxResult = MsgBox("Do you want to save any changes before closing?", MsgBoxStyle.YesNoCancel, "Changes Detected")
If msgResult = MsgBoxResult.Cancel Then
   e.Cancel = True
ElseIf msgResult = MsgBoxResult.Yes Then
   Try
        Me.btnSave.PerformClick() ' Included here is my Saving Code
   Catch ex As Exception
        MsgBox("Unable to Save! " + ex.Message, MsgBoxStyle.Critical, "Error")
        e.Cancel = True
End Try
End If

Jah Bless!!!
 
Here is my code by the way. Hope this will give an idea to those who will view this thread. This is placed inside the Form_Closing event.

I usually recommend people use MessageBox, rather than MsgBox, simply because it makes the code more readable to other .NET developers. Wherever possible, I avoid legacy functions intended to make old VB6 programmers comfortable. Progress requires change!
 
Thanks Man!!! :D

I didn't know that.

Jah Bless!!! :D


Drop Seeds and not your Bombs, Show your Love and not your Arms.
 
Back
Top