Solved

Saving Form's data only if is "Dirty"

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

706 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

19 Experts available now in Live!

Get 1:1 Help Now