Introduction

This control is a quick and dirty component (based on the System.ComponentModel.IExtenderProvider) that allows you to list all the components that have been changed, e.g. to allow you to decide whether a form needs to be saved.

Background

This is a quick and dirty solution to the "how do I know if any data on my form has changed" problem. It allows you to alter the user interface to show that it has changed and also to decide what needs to be saved.

Using the Code

The component has one property: ControlsThatHaveChanged that is a generic list of all the controls whose data has changed since the last reset. If this list isn't empty, then the form has changed and needs to be saved.

There is one method: ResetDirtyFlags which allows you to reset the list of controls that have changed - call this when the form is populated or the data are saved.

In addition, an event is raised whenever a control that is being monitored for changes is changed or changed back to its initial state.

How It Works

The component implements the Implements System.ComponentModel.IExtenderProvider to extend the controls on a form and provides three new properties to each of these controls:

MonitorForChanges - Set to True to monitor a control for changes

ChangeEventToMonitor - Set this to the name of the event to watch (e.g. "ValueChanged" or whichever for the control)

ValueNameToMonitor - Set this to the name of the property that represents the value of the control (e.g. "Text" for a textbox)

Note that these properties are case sensitive which can be a trap for the unwary.

Where a component has this extended property set to True, the component adds a handler to its "Changed" event specified and when that event fires, it updates an internal generic collection of the components that have changed.

The component can be reset (i.e. all controls are marked as unchanged) after a save event or when a record has been refreshed.