none
Detect field change on form in c#? RRS feed

Answers

  • If your controls share the same binding context you can implement INotifyPropertyChanged on the data item to get notified when the binding updates the data source. Or you can save a copy of the old data as the base version so you can compare with the working copy when needed.


    Visual C++ MVP


    Tuesday, July 23, 2013 11:26 PM
    Moderator
  • There is no event that fires whenever any control on the form changes so you'll have to subscribe to each event individually.

    If you have a lot of Controls you may want to try something like the following:

    foreach (Control c in this.Controls)
    {
        if (c is CheckBox)
        {
            ((CheckBox)c).CheckedChanged += c_ControlChanged;
        }
        else
        {
            c.TextChanged += new EventHandler(c_ControlChanged);
        }
    }
    

    Tuesday, July 23, 2013 3:54 PM

All replies

  • There is no event that fires whenever any control on the form changes so you'll have to subscribe to each event individually.

    If you have a lot of Controls you may want to try something like the following:

    foreach (Control c in this.Controls)
    {
        if (c is CheckBox)
        {
            ((CheckBox)c).CheckedChanged += c_ControlChanged;
        }
        else
        {
            c.TextChanged += new EventHandler(c_ControlChanged);
        }
    }
    

    Tuesday, July 23, 2013 3:54 PM
  • If your controls share the same binding context you can implement INotifyPropertyChanged on the data item to get notified when the binding updates the data source. Or you can save a copy of the old data as the base version so you can compare with the working copy when needed.


    Visual C++ MVP


    Tuesday, July 23, 2013 11:26 PM
    Moderator
  • Hi jfalberg,

    Welcome to the MSDN forum!

    I am writing to check the status of the issue on your side.

    What about this problem now?

    Best regards.


    Carl Cai
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 26, 2013 9:35 AM
    Moderator
  • For now I'm using an existing event for textchanged on one of the text fields and referencing to it from all other textbox, combobox, checkbox & datetimepicker fields so I don't have like 50+ different events all doing the same thing that changes a global variable from false to true.
    Friday, July 26, 2013 1:04 PM
  • Hi jfalberg,

    The code from Magnus,and the solution posted by Sheng Jiang can solve your issue.

    I temporarily mark their response as an answer. You can unmark it if they provide no help.

    Best regards.


    Carl Cai
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 31, 2013 5:10 AM
    Moderator