I’m working with a C# WinForm. It has more than a dozen text boxes, combo boxes, and check boxes. The winform displays information that is retrieved from a database. There is a save button on the form that is disabled. I want to be able to enable it when any of the text boxes/combo boxes/ check boxes are changed.
Is there an easy to way to do this without adding separate event handlers to each of these items?
Here is enough to get you stared. You may need to add extra
foreachloops for othercontroltypes as needed. The nice thing is that you only need a few lines of code perControltype, not per instance, with this approach.After modifying the
addHandlersmethod to support all of your controls, and calling it after adding all of the controls to your form, you can simply subscribe to theContentChangedevent for doing whatever might need to happen anytime something on the form changed (i.e. enable/disable a save button).