Control changes in Winform

Posted on 2006-04-19
Last Modified: 2012-08-14
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.

Question by:arody
    LVL 17

    Expert Comment

    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.
    LVL 2

    Accepted Solution

    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,

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    745 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

    16 Experts available now in Live!

    Get 1:1 Help Now