Robotaku
Robotaku

Reputation: 11

display image on click from datagridview

how can i display an image that i already stored in the database to appear on a picturebox when i click on it on the datagridview... i'm still quite new to coding c# so i don't really know how to do this

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {

        if (dataGridView1.SelectedRows.Count > 0)
        {
            string ItemID = dataGridView1.SelectedRows[0].Cells[0].Value + string.Empty;
            string ItemName = dataGridView1.SelectedRows[0].Cells[1].Value + string.Empty;
            string SupplierID = dataGridView1.SelectedRows[0].Cells[2].Value + string.Empty;
            string Quantity = dataGridView1.SelectedRows[0].Cells[3].Value + string.Empty;
            string Price = dataGridView1.SelectedRows[0].Cells[4].Value + string.Empty;

            MemoryStream ms = new MemoryStream();
            Bitmap img = (Bitmap)dataGridView1.CurrentRow.Cells[1].Value;
            img.Save(ms, ImageFormat.Jpeg);
            pictureBox1.Image = Image.FromStream(ms);

            textBox1.Text = ItemID;
            textBox2.Text = ItemName;
            textBox3.Text = SupplierID;
            textBox4.Text = Quantity;
            textBox5.Text = Price;
        }

Upvotes: 1

Views: 248

Answers (1)

Art
Art

Reputation: 11

If I'm understanding your problem correctly, you need to use PictureBox.Refresh(). After setup image use refresh method, for example:

pictureBox1.Image = Image.FromStream(ms);
pictureBox1.Refresh();

Upvotes: 0

Related Questions