Reputation: 2509
I have a datagridview with a datasource MS Access, I use Ole Object data type. The data are shown in the datagridview, But I want the image to be placed in the picturebox when I click on a row/ item, I tried this code, but nothing happens
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
pictureBox2.Image = (Image)dataGridView1.SelectedRows[0].Cells["Picture"].Value;
}
}
Can you help me with this? thanks.
Upvotes: 0
Views: 991
Reputation: 19619
Try this
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count > 0)
{
MemoryStream ms = new MemoryStream(dataGridView1.SelectedRows[0].Cells["Picture"].Value);
pictureBox2.Image = Image.FromStream(ms);
}
}
Upvotes: 1