VB.NET - bind image in vb.net datagridview - Asked By kiruba .e on 19-Jun-12 03:12 AM


I want to bind image from access database into datagridview vb.net windows application, just like binding of text.

So, how to do this?
pls help me

Jitendra Faye replied to kiruba .e on 19-Jun-12 03:25 AM
reference from-


Imports System.Data.SqlClient
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DataGridView1.ColumnCount = 3
        DataGridView1.Columns(0).Name = "Product ID"
        DataGridView1.Columns(1).Name = "Product Name"
        DataGridView1.Columns(2).Name = "Product_Price"

        Dim row As String() = New String() {"1", "Product 1", "1000"}
        row = New String() {"2", "Product 2", "2000"}
        row = New String() {"3", "Product 3", "3000"}
        row = New String() {"4", "Product 4", "4000"}

        Dim img As New DataGridViewImageColumn()
        Dim inImg As Image = Image.FromFile("Image Path")
        img.Image = inImg
        img.HeaderText = "Image"
        img.Name = "img"

    End Sub
End Class
Lalit M replied to kiruba .e on 19-Jun-12 03:27 AM
Use this code
Get The image Path from the database and then do the following :
Dim image As Image =  Image.FromFile("image path")
Dim ImageColumn As DataGridViewImageColumn =  New DataGridViewImageColumn()
ImageColumn.Image = image
ImageColumn.Name = "Name"
ImageColumn.HeaderText = "Nice Name"
dataGridView1.Columns.Insert(0, ImageColumn)

dipa ahuja replied to kiruba .e on 19-Jun-12 03:34 AM
private void button1_Click(object sender, EventArgs e)
  SqlConnection conn = new SqlConnection(Program.c);
  SqlDataAdapter da = new SqlDataAdapter("Select images from pictures", conn);
  DataTable dt = new DataTable();
  //display 1st image
  if (dt.Rows.Count > 0)
    byte[] storedImage = (byte[])dt.Rows[3]["images"];
    Image newImage;
    MemoryStream stream = new MemoryStream(storedImage);
    newImage = Image.FromStream(stream);
    pictureBox1.Image = newImage;
    dataGridView1.Rows[0].Cells[0].Value = newImage;