Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to show your images in the <code>DataGridViewImageColumn</code>, you have to set-up your data like this:</p> <pre><code>dt.Columns.Add("Picture", typeof(byte[])); var actualData = dt.AsEnumerable() .Select(row=&gt; { row.SetField&lt;byte[]&gt;("Picture", GetBytesFromImagePath(row.Field&lt;string&gt;("brandPic")); return row; }).CopyToDataTable(); actualData.Columns.Remove("brandPic"); dgv.DataSource = actualData; //Use this method to get byte[] data from the image path private byte[] GetBytesFromImagePath(string imagePath){ using(MemoryStream ms = new MemoryStream()){ Image img = Image.FromFile(imagePath); img.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); return ms.GetBuffer(); } } //Set-up Header Text dgv.Columns[0].HeaderText = "Brand Name"; dgv.Columns[1].HeaderText = "Brand Picture"; </code></pre> <p><strong>NOTE</strong>: You don't need to add columns to your <code>dgv</code> manually, just set the <code>DataSource</code> as in my code.</p> <p>If you save <code>URL</code> to images instead of <code>local filepath</code>, you can modify the code like this:</p> <pre><code>dt.Columns.Add("Picture", typeof(byte[])); System.Net.WebClient client = new System.Net.WebClient(); int i = 0; client.DownloadDataAsync(new Uri(dt.Rows[0].Field&lt;string&gt;("brandPic")), dt.Rows[0]); client.DownloadDataCompleted += (se, e) =&gt; { ((DataRow)e.UserState).SetField&lt;byte[]&gt;("Picture", e.Result); if(++i == dt.Rows.Count) return; client.DownloadDataAsync(new Uri(dt.Rows[i].Field&lt;string&gt;("brandPic")), dt.Rows[i]); }; dt.Columns.Remove("brandPic"); dgv.DataSource = dt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload