winfrom datagridview ,picturebox,显示图片,以及删除问题


private void write_listview(DataSet ds)
{
DataTable dt = ds.Tables[0];
dataGridView1.DataSource = dt.DefaultView;
for (int i = 0; i < dt.Rows.Count; i++)
{
dataGridView1.Rows[i].Cells["num"].Value = i + 1;
dataGridView1.Rows[i].Cells["image"].Value = GetFile(AppDomain.CurrentDomain.BaseDirectory + @"File\" + dt.Rows[i]["Pic"].ToString());
}
}
/// pictureBox绑定图片
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox2.Image = GetFile(AppDomain.CurrentDomain.BaseDirectory + @"File\" + path);
///
/// 将文件转为内存流
///
///
///
private MemoryStream ReadFile(string path)
{
if (!File.Exists(path))
return null;
using (FileStream file = new FileStream(path, FileMode.Open))
{
byte[] b = new byte[file.Length];
file.Read(b, 0, b.Length); MemoryStream stream = new MemoryStream(b);
return stream;
}
} ///
/// 将内存流转为图片
///
///
///
private Image GetFile(string path)
{
MemoryStream stream = ReadFile(path);
return stream == null ? null : Image.FromStream(stream);
}
or(
public System.Drawing.Image GetImage(string path)
{
FileStream fs = new FileStream(path, FileMode.Open);
Image result = Image.FromStream(fs); fs.Close(); return result; }
)
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
//var s = dataGridView1.Columns[e.ColumnIndex].Name;
path = dataGridView1.Rows[e.RowIndex].Cells["imagepath"].Value.ToString();
id = dataGridView1.Rows[e.RowIndex].Cells["Column2"].Value.ToString();
if (dataGridView1.Columns[e.ColumnIndex].Name == "image")
{
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox2.Image = GetFile(AppDomain.CurrentDomain.BaseDirectory + @"File\" + path); }
if (dataGridView1.Columns[e.ColumnIndex].Name == "Column_del")
{
pictureBox2.Image = null;
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"File\" + path))
{
File.Delete(AppDomain.CurrentDomain.BaseDirectory + @"File\" + path);
}
string sqlstr = "DELETE from [Image] where ID= '" + id + "'";
int count = SQLiteHelper.ExecuteNonQuery(sqlstr);
if (count > 0)
{
this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[e.RowIndex]);
MessageBox.Show("删除成功!");
sqlstr = "SELECT * FROM [Image] where [EID]='" + editsrt + "'";//"SELECT * FROM [Image] where EID='" + eid + "'";
DataSet ds_img = SQLiteHelper.ExecuteQuery(sqlstr);
write_listview(ds_img); } }
winfrom datagridview ,picturebox,显示图片,以及删除问题的更多相关文章
- EmguCV控件Emgu.CV.UI.ImageBox及C# picturebox显示图片连续刷新出现闪烁问题
在上一篇里,EmguCV(OpenCV)实现高效显示汉字及叠加 实现了视频叠加及显示,但存在问题,就是 Emgu.CV.UI.ImageBox及C# picturebox显示图片时都会出现闪烁,尤其 ...
- C#winfrom listview 设置显示图片
ListView控件有5种显示图片方式:LargeIcon(大图标),Detail(详细),SmallIcon(小图标),List(列表),Tile,常用前4种. 这里说一下设置方式:LargeIc ...
- [WinForm]- 设置DataGridView单元格内根据不同值显示图片
首先设置要显示图片的列 DataGridViewImageColumn status = new DataGridViewImageColumn(); status.DisplayIndex = ; ...
- 如何使用SOIL在VS2012的 C++环境下显示图片
先看下效果. 这是一个很无聊的功能....首先说下,我做这个功能的初衷并不是为了实现在控制台中显示图片...(这貌似很无聊) 而是因为自己想做用C做一个游戏:http://q.cnblogs.com/ ...
- While readingiphone真机无法显示图片,而模拟器可以正常显示
可能,很多开发IOS程序的遇到过在模拟器里,加载图片都是正常的,但是在真机里就会出现图片资源不能加载的问题. 其中一种原因是,在Simulator里面,例如:图片资源名称为:a.PNG,在代码你里,你 ...
- 利用COM组件IPicture读取jpg、gif、bmp图片文件数据和显示图片
1.读取图片数据 函数原型:bool LoadImage(const char *pName, unsigned char *pBitData); 函数功能,读取pName指向的图片文件的位图数据 b ...
- 我写的一个 Qt 显示图片的控件
Qt 中没有专门显示图片的控件.通常我们会使用QLabel来显示图片.可是QLabel 显示图片的能力还是有点弱.比方不支持图像的缩放一类的功能.使用起来不是非常方便. 因此我就自己写了个简单的类. ...
- FrameBuffer系列 之 显示图片
摘自:http://blog.csdn.net/luxiaoxun/article/details/7622988 #include <unistd.h> #include < ...
- winfrom中pictureBox控件的部分使用方法
一.后台属性 1.pictureBox1.Image显示图片 2.pictureBox1.ImageLocation存储和提取图片路径 二.面板属性 1.Picturebox控件SizeMode属性 ...
随机推荐
- Eclipse启动参数设置
Eclipse启动参数设置 文件路径:安装目录根路径/eclipse.ini 参数注解: [-debug options -vm javaw.exe] 显示JVM当前内存使用量(注:详见下方<让 ...
- 20145208 蔡野 《网络对抗》Exp8 Web基础
20145208 蔡野 <网络对抗>Exp8 Web基础 本实践的具体要求有: (1).Web前端HTML(1分) 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POS ...
- NOI 2007 货币兑换Cash (bzoj 1492) - 斜率优化 - 动态规划 - CDQ分治
Description 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和 B纪念券(以下 简称B券).每个持有金券的顾客都有一个自己的帐户.金券的数目可以是一个 ...
- xlrd与xlwt的下载
读excel表格: xlrd 地址:https://pypi.org/project/xlrd/ 下载语句:pip install xlrd 写excel表格: xlwt https://pypi.o ...
- 洛谷luogu2782
P2782 友好城市 题目描述 有一条横贯东西的大河,河有笔直的南北两岸,岸上各有位置各不相同的N个城市.北岸的每个城市有且仅有一个友好城市在南岸,而且不同城市的友好城市不相同.每对友好城市都向政府申 ...
- CentOS7.2中systemctl的使用
CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替. 1.原来的 service 命令与 s ...
- 【问题解决】连接mysql 8错误:authentication plugin 'caching_sha2_password
在刚安装好mysql8,使用native连接的时候报错 authentication plugin 'caching_sha2_password'... 首先确保服务已开启,然后通过cmd命令进入my ...
- html 之 body topmargin、leftmargin、rightmargin、bottomnargin
基本语法 <body topmargin=value leftmargin=value rightmargin=value bottomnargin=value> 语法说明 通过设置top ...
- Sql Ado.net 学习笔记之连接字符串
https://www.cnblogs.com/heng95/p/5902019.html 连接字符串 SQL Client .net数据提供程序在连接到数据库时极其灵活,它提供了多种用以生成连接字符 ...
- 论文笔记:Attention Is All You Need
Attention Is All You Need 2018-04-17 10:35:25 Paper:http://papers.nips.cc/paper/7181-attention-is-a ...