title: Getting Images and bindingSource.Filter working together in a DataGridView
body: <p>I populate a DataGridView from a collection serialized to a string of XML (example code: *).</p>
  
  <p>My requirements are (1) to get images into the DataGridView and (2) the ability to set the bindingSource.Filter string and dynamically filter the table based on strings in the columns (for possibly thousands of entries). My weird XML to string hack below works for Filter but I cannot de/serialize the Images to/from string so I cannot create a magic DataView where .Filter works correctly.</p>
  
  <p>Question(s): (a) Is there a better way to get a DataView collection of objects from RAM into the dataGridView than serializing to an XML string (to get a DataView) <i>with the caveat that .Filter still works</i>. (b) Is there an alternate way to add stuff to the bindingSource/DataView at run-time (especially the Image column) which preserves the use of .Filter?</p>
  
  <p>From my tests, doing things <a href="http://msdn.microsoft.com/en-us/library/y0wfd4yz.aspx" rel="nofollow noreferrer">this way (How to: Bind Objects to Windows Forms DataGridView Controls)</a> makes setting the Filter field inoperable, i.e. do nothing, no Exception, no magic filtering, nada.</p>
  
  <p>(*)</p>
  
  <pre><code>    // objects in each row
      [Serializable]
      public class GradorCacheFile
      {
          public Bitmap image;
          public string filename;
  
          // to make it serializable
          public GradorCacheFile()
          {
          }
  
          public GradorCacheFile(GradorCacheFile old)
          {
              this.filename = old.filename;
              this.image = old.image;
          }
      }
  
  // snippet of class:
  public List&lt;GradorCacheFile&gt; files = null;
  void Process()
  {
      GradorCacheFiles gcf = new GradorCacheFiles();
      gcf.AddRange(this.files);
  
      XmlSerializer xs = new XmlSerializer(typeof(GradorCacheFiles));
      StringWriter sw = new StringWriter();
      xs.Serialize(sw, gcf);
      sw.Close();
  
      string xml = sw.ToString();
  
      StringReader reader = new StringReader(xml);
      DataSet ds = new DataSet();
      ds.ReadXml(reader);
      if (ds.Tables.Count &lt; 1)
          return;
  
      DataTable dt = ds.Tables[0];
      DataView dv = new DataView(dt);
      this.bindingSource = new BindingSource();
      this.bindingSource.DataSource = dv;
      this.dataGridView.DataSource = this.bindingSource;
  
      int rows = this.dataGridView.Rows.Count;
      if (rows == 0)
          return;
      this.dataGridView.Columns[0].HeaderText = "Image";
      this.dataGridView.Columns[1].HeaderText = "File";
  }
  </code></pre>