By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,497 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,497 IT Pros & Developers. It's quick & easy.

Before closing form, detecting if changes to data had been made -How?

P: n/a
Bob
Using Vs 2005 and Vb.NET I want to give users a message asking if they're
sure they want to close the form if they had made changes to the underlying
data. How do I detect if changes had been made by user but not yet saved?

Thanks,

Bob
Jan 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
the Dataset object offers a "HasChanges" property which will be true
unless you've called AcceptChanges (or haven't made any changes). I
don't know if Datatables offer that same property or not, however.

Here is what I used in the past, and it seems to work fine.

Private Sub frmDocInfoMaster_FormClosing(ByVal sender As Object,
ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles
Me.FormClosing
'
'Check to see if there are any pending changes before closing
the form, if so
'ask the user if they'd like to save changes before exiting
'
Dim dlgResult As DialogResult

If Me.DsRFA1.HasChanges Then
dlgResult = MessageBox.Show("Do you wish to save changes?",
"Contact Info Master", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Warning)
Select Case dlgResult
Case Windows.Forms.DialogResult.Yes

adpContactInfoMaster.Update(Me.DsRFA1.tblDocInfoMa ster)
e.Cancel = False
Case Windows.Forms.DialogResult.No
e.Cancel = False
Case Windows.Forms.DialogResult.Cancel
e.Cancel = True
End Select
End If
End Sub

Jan 3 '06 #2

P: n/a

Depends on what is on the form. You might compare the current state
with a snapshot of the last saved state. Or you might set an "IsDirty"
form member flag (or similarly named) to True every time anything is
modified on the form, then check this flag on exit.

The former approach will give you a more detailed view of what has
changed. The latter only an indication that something has changed.

One drawback of the latter approach is also that you cannot detect
if something was changed to something else, then back to the original
state, in which case you could have considered the form to be non-
changed.

I am sure there are plenty of patterns for dealing with this problem.

If you are working with bound controls, you might have to check
the documentation for the objects in use for information about what
I have described above.

Regards,

Joergen Bech

On Tue, 3 Jan 2006 13:39:09 -0500, "Bob" <bd*****@sgiims.com> wrote:
Using Vs 2005 and Vb.NET I want to give users a message asking if they're
sure they want to close the form if they had made changes to the underlying
data. How do I detect if changes had been made by user but not yet saved?

Thanks,

Bob


Jan 3 '06 #3

P: n/a
I have found that the best way is to store an object containing the original
displayed data then when the user closes the form, get the new data from the
display into another object then compare the two object. Anything else I've
had trouble with and required a lot of extra workarounds to get the UI
correct.

P.S. I hope I never have to use an application that uses bound controls for
editing database records!
--
Dennis in Houston
"Bob" wrote:
Using Vs 2005 and Vb.NET I want to give users a message asking if they're
sure they want to close the form if they had made changes to the underlying
data. How do I detect if changes had been made by user but not yet saved?

Thanks,

Bob

Jan 4 '06 #4

P: n/a
Bob
Why no bound controls and if not what do you do to fill stuff like
datagridviews and navigate?

Just curious, Thanks,
Bob
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
I have found that the best way is to store an object containing the
original
displayed data then when the user closes the form, get the new data from
the
display into another object then compare the two object. Anything else
I've
had trouble with and required a lot of extra workarounds to get the UI
correct.

P.S. I hope I never have to use an application that uses bound controls
for
editing database records!
--
Dennis in Houston
"Bob" wrote:
Using Vs 2005 and Vb.NET I want to give users a message asking if they're
sure they want to close the form if they had made changes to the
underlying
data. How do I detect if changes had been made by user but not yet saved?

Thanks,

Bob

Jan 4 '06 #5

P: n/a
I was referring to using bound controls to "Edit" a data base at the UI
level. I don't have a problem binding datatables, etc, to datagrids but if
you are going to use this for editing the database, you will find a lot of
limitations.

I ask the following question on this usegroup once:
"Has anyone actually used bound controls for editing a database in a
commercial application that was marketed"
I got a lot of complaints about how great bound controls were but NO ONE
replied that they had actually used this in a real commercial application. I
also got some replies that they didn't think bound controls were useful for
anything but non-commercial applications due to the restrictions when using
for a real UI interface.

--
Dennis in Houston
"Bob" wrote:
Why no bound controls and if not what do you do to fill stuff like
datagridviews and navigate?

Just curious, Thanks,
Bob
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:E6**********************************@microsof t.com...
I have found that the best way is to store an object containing the
original
displayed data then when the user closes the form, get the new data from
the
display into another object then compare the two object. Anything else
I've
had trouble with and required a lot of extra workarounds to get the UI
correct.

P.S. I hope I never have to use an application that uses bound controls
for
editing database records!
--
Dennis in Houston
"Bob" wrote:
Using Vs 2005 and Vb.NET I want to give users a message asking if they're
sure they want to close the form if they had made changes to the
underlying
data. How do I detect if changes had been made by user but not yet saved?

Thanks,

Bob


Jan 5 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.