Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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
0
arody
Asked:
arody
1 Solution
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now