473,382 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
5 10954
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

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Terry | last post by:
I need some help refining an MS 2000 relational databse. I have created a simple relational database using two tables, 'Student Details', 'Exam Details' and two forms, 'Input/Edit Exam Details',...
1
by: saleem | last post by:
Dear friends, I am working on the problem which deals with the data management of requests and how should we match the responses for the requests to compare the correct Response. my problem...
5
by: needin4mation | last post by:
Hi, I have an asp.net 1.1 application that populates data from a database. When the user changes data, they have to hit a button to update the data. The data entry form (same form that is...
0
by: Bob | last post by:
I have a form (VB 2003) with bound controls. Before closing the form I call Me.BindingContext(dataSet, "table").EndCurrentEdit then check the dataSet.HasChanges property to see if I need to save...
2
by: sureshgv | last post by:
window.onbeforeunload = confirmExit; function confirmExit() { if (needToConfirm) { return "You have attempted to leave this page. If you have made any changes to the fields...
3
by: Darin | last post by:
I have a problem I just can't figure out. I have a form with a subform, and the recordsource of the subform has criteria based on some unbound fields in the parent form so that data in the parent...
6
by: trbjr | last post by:
Hello experts, I want to describe a project design and then ask some questions at the end. There is no code in this discussion, just symbols to illustrate an idea. Let S stand for a screen...
2
by: jmarcrum | last post by:
Hi everyone!! I have a problem. I have a form for entering new data. If the user clicks the button on my frmMain (cmdAdd), the form for entering new data appears. However, IF the user decides...
7
by: fachagooch | last post by:
When i click on the Save button in the interface it executes the SaveData() steps. but i am being told that i need to update the date stamp on the Access file. any ideas as to how i would make...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.