使用DataSet存储图像并使用DataGridView显示它们 [英] Storing images with DataSet and Displaying them with DataGridView

查看:57
本文介绍了使用DataSet存储图像并使用DataGridView显示它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个winforms应用程序,它将接收用户数据并将其存储在DataTable中,直到将其保存到Excel工作表。

I am trying to create an winforms app that will take in user data over and store it in a DataTable until it is saved to an excel sheet.

我的问题是目前我将图像作为字节数组存储在DataTable中。虽然这会存储它们,但绑定到表的DataGridView无法显示它们。

My issue is that currently I am storing the images in the DataTable as a byte array. While this does store them, the DataGridView that is bound to the table is not able to display them.

我的代码看起来像这样。

My code looks something like this.

public byte[] StoreImage()
{
   Rectangle rekt = new Rectangle(3, 3, myPictureBox.Width, 
   myPictureBox.Height);

   Bitmap myImage = new Bitmap(myPictureBox, 
   myPictureBox.Width, 
   myPictureBox.Height);

   myPictureBox.DrawtoBitmap(myImage, rekt);

   MemoryStream ms = new MemoryStream();

   myImage.Save(ms, ImageFormat.Bmp);
   byte[] myImageBytes = ms.ToArray();

   return myImageBytes;
}

private void AddPicRow()
{
   DataRow row = myTable.NewRow();

   row[1] = DateTime.Now.ToString(hh:mm:ss tt);
   row[2] = StoreImage();

   myTable.Rows.Add(row);
}


我错过了一些简单的东西吗?喜欢属性设置还是演员表?

Am I missing something simple? Like a property setting or a cast?

如果可能,我希望能够双击单元格来显示/调整大小。

If possible I would like to be able to double click on the cell to display/resize it.

推荐答案

您好,

您是否将byte []的DataGridView列设置为a DataGridViewImage列?如果没有那么那应该有效。

Did you set the DataGridView column for the byte[] to a DataGridViewImage column ? If not then that should work.


这篇关于使用DataSet存储图像并使用DataGridView显示它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆