Control changes in Winform

I have a form with many dropdown boxes, textboxes, and date selections.

I need to find out at a form level before I close the form whether any of the values in any of the controls in the form changed.  This way I know whether or not I need to save the data by running another sub that will get the values and update them to the database.

I am not using datasets or datatables to store/retrieve values.  I read values from a sqldatareader and put the values in the appropriate form controls.  Then when closing form I loop through all of the controls and save values to database.

Please help, I come accross this all the time and need an answer very quickly.

Thanks,
Eli
arodyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZeonFlashCommented:
If you're not storing what the data values were originally, and your not binding the controls to a dataset, then you've taken away the easy answer.  My suggestion would be to execute your datareader again and check the form values vs. the database values.  If any comparison shows they are not the same, then fire your save routine.
0
Omar McKoyHead of Infrastructure OperationsCommented:
You could have one method that handles all the change events of the controls, see example below:

Dim bFormChanged As Boolean = False

Public Sub DataChanged(ByVal sender As Object, ByVal e As EventArgs)) Handles cmb1.IndexChanged, cmb2.IndexChanged, txt1.TextChanged

             bFormChanged = True

             ' Other code, eg. disable menu items etc.
End Sub

Now all you need to do is check this boolean value to see if any of the values were modified on the form.

Best regards,
Real_McKoy
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.