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属性 ...
随机推荐
- vue中的指令v-model
Vue的指令:其实就是单个JavaScript表达式,一般来说是带有v-前缀:都有着对应的官网介绍:https://cn.vuejs.org/v2/guide/forms.html v-model:数 ...
- PostgreSQL 10首个测试版本发布
mysql 从5.7到8.0,pg从9.6到10,干起来了.. PostgreSQL 10 的首个测试版发布了,此版本包含 PostgreSQL 10 最终将提供的所有功能的预览.当然,有些细节将在最 ...
- 【题解】bzoj 4327 JSOI2012 玄武密码
原题传送门 我们先对所有询问串建立AC自动机(今天洛咕上有人分不清AC自动机和自动AC机) 然后将母串在AC自动机上跑,每走到一个点x,从x点出发沿着fail指针所能到的所有前缀都是匹配成功的,暴力向 ...
- vue 起步
vue 官网 目前最火的前端框架当属Vue.js了,很多使用过vue的程序员这样评价它,“vue.js兼具angular.js和react.js的优点,并剔除了它们的缺点”.授予了这么高的评价的vue ...
- Java中断异常 InterruptedException 的正确处理方式
你看到这篇文件可能是因为你已经调用了一个抛出 InterruptedException 异常的方法,并且需要以某种方式处理它. 首先,需要了解为一个方法为啥会 throws InterruptedEx ...
- NLTK 知识整理
NLTK 知识整理 nltk.corpus模块自带语料 NLTK comes with many corpora, toy grammars, trained models, etc. A compl ...
- batchGetAnchorLevel(dubbo接口)
一.编写脚本前的准备工作 1.安装idea,安装本地maven库,并在idea里面配置maven 2.导入git源码(目的在于下载所依赖的基础包)-->File-new-Project from ...
- topcoder srm 713 div1
problem1 link 如果$a^{b}=c^{d}$,那么一定存在$t,x,y$使得$a=t^{x},c=t^{y}$.一旦$t,x,y$确定,那么可以直接计算出二元组$b,d$有多少.对于$t ...
- 编译openwrt时报错:FMCGenericError.h:34:27: fatal error: libxml/parser.h: No such file or directory
解决办法: 更新openwrt的feeds,并重新make menuconfig ./script/feeds update -a ./script/feeds install -a
- tp框架中的一些疑点知识-6
vim自带一个目录浏览器,使用命令:E就可以调出来,实际上就是浏览器的名字就是"网络读写"netrw vim也自带了 补全功能, 启动键是 "ctrl_N" 或 ...