Solved

Saving Form's data only if is "Dirty"

Posted on 2009-04-14
2
504 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now