title: ObservableCollection<T> in Winforms and possible alternatives
body: <p>Winforms .net 3.5 app. In my app I have a generic class that looks like so:</p>
  
  <pre><code>public class FilterItem {
    public FilterItem() { }
    public string FilterProperty { get; set; }
    public bool FilterPropertyChecked { get; set; }
    public ComparitiveOperator FilterOperator { get; set; }
    public string FilterValue { get; set; }
  }
  </code></pre>
  
  <p>and I use it in all of my dialog boxes when I want to implement some sort of filter functionality.  So I call the dialog form with a pre-poulated <code>List&lt;FilterItem&gt;</code> passed in the constructor. Now when the dialog loads, it iterates thru each list-item and adds:</p>
  
  <ol>
  <li>A checkbox</li>
  <li>A combobox</li>
  <li>A textbox</li>
  </ol>
  
  <p>to every row in a TableLayoutPanel. The Checkbox gets its text property from <code>FilterProperty</code> and its Checked status from <code>FilterPropertyChecked</code>...the Combobox gets its binding from <code>FilterOperator</code>...and the Textbox gets its text value from <code>FilterValue</code>.</p>
  
  <p>Notice how Im only saying <strong><em>gets</em></strong>.  What I would like to do is automatically update these properties when the Controls whose properties they are bound to change.  I heard about <code>ObservableCollection&lt;T&gt;</code> but I dont seem to have 'access' to it in Winforms after adding the <code>System.Collections.ObjectModel</code> namespace.</p>
  
  <p>What would be the best way to accomplish this. BindingList with INotifyPropertyChanged??  Im not an expert with the latter, and would greatly appreciate some pointers - if this is the way I should be going.</p>
  
  <p>thank u!</p>
  
  <p><strong><em>EDIT:</em></strong></p>
  
  <p>Ok, let me post some code to show what I think I should be doing :). I know I need to implement <code>INotifyPropertyChanged</code> on my FilterItem class, so (just for the FilterValue part for example):</p>
  
  <pre><code>public class FilterItem : INotifyPropertyChanged {
      public FilterItem() { }
      public string FilterProperty { get; set; }
      public bool FilterPropertyChecked { get; set; }
      public ComparitiveOperator FilterOperator { get; set; }
  
      private string _FilterValue;
      public string FilterValue {
          get { return this._FilterValue; }
          set {
              if (this._FilterValue != value) {
                  this._FilterValue = value;
                  this.OnFilterValueChanged();
              }
          }
      }
  
      #region INotifyPropertyChanged Members
      protected void OnFilterValueChanged() {
          var handler = this.PropertyChanged;
          if (handler != null) {
              handler(this, new PropertyChangedEventArgs("FilterValue"));
          }
      }
      public event PropertyChangedEventHandler PropertyChanged;
      #endregion
  }
  </code></pre>
  
  <p>Now it <em>should</em> all come together in my Form_Load (this is just for the Textbox part and I have omitted the Checbox and ComboBox) like so:</p>
  
  <pre><code>private List&lt;FilterItem&gt; FilterList; // &lt;-- this gets assigned to in the constructor
  
  private void dlgFilterData_Load(object sender, EventArgs e) {
      foreach (FilterItem item in FilterList) {
          txt = new TextBox();
          txt.DataBindings.Add("Text", item, "FilterValue", false, DataSourceUpdateMode.OnPropertyChanged);
          txt.Dock = DockStyle.Fill;
      }
  }
  </code></pre>
  
  <p>the textbox's databindings DataSource is the FilterItem 'item'. But now I seem to be having a problem with my visual studio IDE, so cant try this out, but will when I have it up and running.  What I would like to know now is:  will this setup successfully assist in allowing my individual <code>FilterItem</code>s to get automatically updated when their assigned Control's respective property changes??</p>