从datagridview点击显示图像

时间:2017-03-19 07:48:28

标签: c# mysql

当我在datagridview上点击它时,我怎样才能显示我已经存储在数据库中的图像以显示在图片框上...我仍然很新编码c#所以我不想真的知道怎么做

  

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;
        }

1 个答案:

答案 0 :(得分:0)

如果我正确理解您的问题,您需要使用PictureBox.Refresh()。设置图像后使用刷新方法,例如:

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