title: View a serialized image class as a image data field (DataSet as datasource for DataGridView)
body: <p>At first, thanks for reading my problem.
  <br /><br /></p>
  
  <h2><strong>The Background</strong></h2>
  
  <p>Im working on a DataGridView which use a pre-existing XML file as datasource:</p>
  
  <pre><code>public DataSet TableDatabase = new DataSet();
  TableDatabase.ReadXml("xml_file.xml");
  (DataGridView)DbTable.DataSource = TableDatabase.Tables[0];
  </code></pre>
  
  <p>The base xml file is a generic database with id, int, text. 
  <br /><br /></p>
  
  <h2><strong>What I want to do</strong></h2>
  
  <p>What I basicly want to do, is to add a new column with typeof Bitmap (source from clipboard) <strong>and</strong> serialize it as Base64 "string".</p>
  
  <p>If I use the first line "typeof(Bitmap)", the image data will be shown as image, but no idea how to serialize it...</p>
  
  <pre><code>// DataColumn col = TableDatabase.Tables[0].Columns.Add("columnname", typeof(Bitmap));
  DataColumn col = TableDatabase.Tables[0].Columns.Add("columnname", typeof(MyImage));
  </code></pre>
  
  <p>I made a Class called "MyImage" (based on <a href="https://stackoverflow.com/questions/1907077/serialize-a-bitmap-in-c-net-to-xml">Serialize a Bitmap in C#/.NET to XML</a>):</p>
  
  <pre><code>[Serializable]
  public class MyImage : IXmlSerializable
  {
      public Bitmap Image { get; set; }
      public System.Xml.Schema.XmlSchema GetSchema()
      {
          return null;
      }
      public void ReadXml(System.Xml.XmlReader reader)
      {
          reader.ReadStartElement();
          MemoryStream ms = null;
          byte[] buffer = new byte[256];
          int bytesRead;
          while ((bytesRead = reader.ReadContentAsBase64(buffer, 0, buffer.Length)) &gt; 0)
          {
              if (ms == null)
              {
                  ms = new MemoryStream(bytesRead);
              }
              ms.Write(buffer, 0, bytesRead);
          }
          if (ms != null)
          {
              Image = (Bitmap)System.Drawing.Image.FromStream(ms,true,true);
          }
          reader.ReadEndElement();  
      }
      public void WriteXml(System.Xml.XmlWriter writer)
      {
          using (MemoryStream ms = new MemoryStream())
          {
              Image.Save(ms, ImageFormat.Bmp);
              byte[] bitmapData = ms.ToArray();
              writer.WriteBase64(bitmapData, 0, bitmapData.Length);
          }
      }
  }
  </code></pre>
  
  <p>Its working really nice, I can load and write the imagedata in xml:</p>
  
  <pre><code>&lt;columnname&gt;...base64 data...&lt;/columnname&gt;
  </code></pre>
  
  <p><br /></p>
  
  <h2><strong>The Problem</strong></h2>
  
  <p>The Datafield in the DataGridView will not show as image :(</p>
  
  <p>It just shows a string: "<strong>Namespace.MyImage</strong>". So how can I tell the DataCell to show the image?</p>