title: Can my binding source tell me if a change has occurred?
body: <p>I have a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx" rel="noreferrer"><code>BindingSource</code></a> that I'm using in winforms data binding and I'd like to have some sort of prompt for when the user attempts to close the form after they've made changes to the data.  A sort of "Are you sure you want to exit without saving changes?"</p>
  
  <p>I'm aware that I can do this via the <code>BindingSource</code>'s <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.currencymanager.itemchanged(v=VS.90).aspx" rel="noreferrer"><code>CurrencyManager.ItemChanged</code></a> event by just flipping a "has changed" boolean. </p>
  
  <p>However, I want a more robust functionality.  <strong>I'd like to know when the current data is different from the original data.</strong>  The event just tells me if somethings changed.  A user could still change a property, hit undo, and I would still think that there is a change in the data to save.</p>
  
  <p>I want to mimic this similar functionality of notepad</p>
  
  <ul>
  <li>open notepad</li>
  <li>type something</li>
  <li>delete everything (essentially undoing what you did)</li>
  <li>close notepad, notepad closes, no prompt to save changes because it knows the end state == the initial state</li>
  </ul>
  
  <p>If this is not possible, then should I go with the <code>ItemChanged</code> event handler as outlined above or is there a better way?</p>
  
  <p>For the record, I'm looking for something along the lines of </p>
  
  <pre><code>bool HasChanged()
  {
      return this.currentState != this.initialState;
  }
  </code></pre>
  
  <p>not this</p>
  
  <pre><code>bool HasChanged()
  {
      // this._hasChanged is set to true via event handlers
      return this._hasChanged;
  }
  </code></pre>
  
  <p>I'd just rather not have to manage the current state and the initial state myself, I'm looking for a way to grab that info from the <code>BindingSource</code>  If I can get this functionality from the <code>BindingSource</code> its way more ideal since I will be able to use the functionality on many different data sources, regardless of type, etc.</p>