c# - 从datagridview点击显示图像

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

最佳答案

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

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

关于c# - 从datagridview点击显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42884188/

相关文章:

C# 最佳实践 : Unit Testing code that refers to utilizes other methods?

php - 如何使用 phalcon 上传多个图像并将其名称存储在数据库中?

mysql - 两列使用 SUM 和 GROUPED 的 SQL

c# - 非常规年份的 DateTime.ParseExact

c# - 为什么我们需要在 Html.BeginForm 中使用@using

mysql - 从 vbscript 连接到 mysql 时用户对数据库的访问被拒绝

MySQL IF语句语法错误

mysql - 避免插入重复的列值

c# - 获取成功的 Ajax 操作以打开另一个弹出窗口

c# - 如何在 WPF 的 Datagrid 行标题中居中对齐行号