Solved

Saving Form's data only if is "Dirty"

Posted on 2009-04-14
2
508 Views
Last Modified: 2013-12-26
Hi everyone,

In a VB.NET 2005 - WINDOWS application:

I have an application with about 50 forms that needs to be refractored in a way that the user does not have to press the "Save" button every time he makes a change... instead, the form on the close event should know that the form is "Dirty" and commit the changes.

There is no binding to a dataset (as it should) otherwise will be easy  to do the trick.

I do not want to update the records firing the click-event of the the save button if there are no changes because it makes difficult to track who made actual changes on the database and will create un-necessary network traffic.

How can I accomplish this?

I'm thinking of adding an event handler for each of the fields for the event changed and modify a flag "Dirty"
is this the way to do it?

Any ideas are welcome,

Regards

Jorge
       

0
Comment
Question by:George
2 Comments
 
LVL 9

Accepted Solution

by:
djon2003 earned 500 total points
ID: 24140056
What I would do is :
-Marking all the controls needing dirtying with his Tag property to "DIRTYING".
-Add each form a variable called IsDirty and set it to false.
-Create a sub which loops through all the form controls (and also recursively looking to control subcontrols) and if the Tag property = "DIRTYING" then you do AddHandler depending on the type of control (ie. Checkbox would be Addhandler curControl.Checked, AddressOf ControlChecked ..... or a TextBox woul be Addhandler curControl.TextChanged, AddressOf ControlTextChanged ) The method called by the AddressOf set the IsDirty variable to True.
-When you first load your data, the IsDirty will be to True, so reset it to False. (After loading)
-Then, looking at this variable will tell you if the user has done any changes in the control demanded. If so, you can do what ever action needed.
0
 

Author Closing Comment

by:George
ID: 31569935
I think this could do the trick.
Thank you very much!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question