当我在 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/