【发布时间】:2016-05-02 10:55:45
【问题描述】:
我有一个带有列类型图像的数据网格视图。我想从数据网格中获取值到我正在使用的图片框。这是我在 CellClick 中的代码
byte[] image = (byte[])dgv_salesquotesummary.Rows[e.RowIndex].Cells[7].Value;
MemoryStream ms = new MemoryStream(image);
pb_productImage.Image = Image.FromStream(ms);
我收到这个错误提示
Additional information: Unable to cast object of type 'System.Drawing.Bitmap' to type 'System.Byte[]'.
提前谢谢你!
【问题讨论】:
-
该单元格的值已经是位图,因此无需将它们转换为 byte[],如果需要,只需将其转换为 Image。
-
什么意思?请以代码格式创建您的答案,以便我可以尝试测试它:)
-
pb_productImage.Image = (Image)(((Bitmap)dgv_salesquotesummary.Rows[e.RowIndex].Cells[7].Value).Clone())
-
先生,感谢您现在的工作。请将您的答案放在“答案”框中,以便我将其标记为“已回答”,非常感谢先生!