Solved

Saving Form's data only if is "Dirty"

Posted on 2009-04-14
2
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

738 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