Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Saving Form's data only if is "Dirty"

Posted on 2009-04-14
2
Medium Priority
?
513 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

885 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