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,显示图片,以及删除问题的更多相关文章

  1. EmguCV控件Emgu.CV.UI.ImageBox及C# picturebox显示图片连续刷新出现闪烁问题

    在上一篇里,EmguCV(OpenCV)实现高效显示汉字及叠加  实现了视频叠加及显示,但存在问题,就是 Emgu.CV.UI.ImageBox及C# picturebox显示图片时都会出现闪烁,尤其 ...

  2. C#winfrom listview 设置显示图片

    ListView控件有5种显示图片方式:LargeIcon(大图标),Detail(详细),SmallIcon(小图标),List(列表),Tile,常用前4种.  这里说一下设置方式:LargeIc ...

  3. [WinForm]- 设置DataGridView单元格内根据不同值显示图片

    首先设置要显示图片的列 DataGridViewImageColumn status = new DataGridViewImageColumn(); status.DisplayIndex = ; ...

  4. 如何使用SOIL在VS2012的 C++环境下显示图片

    先看下效果. 这是一个很无聊的功能....首先说下,我做这个功能的初衷并不是为了实现在控制台中显示图片...(这貌似很无聊) 而是因为自己想做用C做一个游戏:http://q.cnblogs.com/ ...

  5. While readingiphone真机无法显示图片,而模拟器可以正常显示

    可能,很多开发IOS程序的遇到过在模拟器里,加载图片都是正常的,但是在真机里就会出现图片资源不能加载的问题. 其中一种原因是,在Simulator里面,例如:图片资源名称为:a.PNG,在代码你里,你 ...

  6. 利用COM组件IPicture读取jpg、gif、bmp图片文件数据和显示图片

    1.读取图片数据 函数原型:bool LoadImage(const char *pName, unsigned char *pBitData); 函数功能,读取pName指向的图片文件的位图数据 b ...

  7. 我写的一个 Qt 显示图片的控件

    Qt 中没有专门显示图片的控件.通常我们会使用QLabel来显示图片.可是QLabel 显示图片的能力还是有点弱.比方不支持图像的缩放一类的功能.使用起来不是非常方便. 因此我就自己写了个简单的类. ...

  8. FrameBuffer系列 之 显示图片

     摘自:http://blog.csdn.net/luxiaoxun/article/details/7622988 #include <unistd.h> #include < ...

  9. winfrom中pictureBox控件的部分使用方法

    一.后台属性 1.pictureBox1.Image显示图片 2.pictureBox1.ImageLocation存储和提取图片路径 二.面板属性 1.Picturebox控件SizeMode属性 ...

随机推荐

  1. python之接口与抽象类

    一.接口与归一化设计 1.什么是接口 1)是一组功能集合 2)接口的功能是用于交互 3)接口只定义函数,但不涉及函数的实现 4)这些功能是相关的 2.为什么要用接口 接口提取了一群类共同的函数,然后让 ...

  2. paymob QB冲值接口

    static string PostPaymob() { string url = "http://www.paymob.cn/getorderinfo/index"; //统一分 ...

  3. charles最新破解jar文件,及浏览器证书安装

    一 在线破解文件下载 Charles 在线破解工具,https://www.zzzmode.com/mytools/charles/ 描述 此工具用于生成破解后的charles.jar文件,  破解原 ...

  4. phpstorm中设置代码上传到github

    参考: https://blog.csdn.net/Knight_quan/article/details/54894691 https://www.300168.com/biancheng/show ...

  5. NSIS+Duilib 制作Windows安装包

    转载:https://www.cnblogs.com/zzllily/articles/5443850.html 转载:https://blog.csdn.net/bruce135lee/articl ...

  6. topcoder srm 684 div1

    problem1 link 首先由$P$中任意两元素的绝对值得到集合$Q$.然后枚举$Q$中的每个元素作为集合$D$中的最大值$Max$,这样就能确定最后集合$D$中的最小值要大于等于$Min=\fr ...

  7. topcoder srm 695 div1 -3

    1.称一个串的子串(连续一段)为$same$当且仅当这个子串所有字符都一样.子串不同当且仅当在原串中的起始位置不同.现在构造一个长度为$n$的只包含字符'a','b'的串$s$,使得$s$满足长度为$ ...

  8. Golang模拟客户端POST表单功能文件上传

    客户端通过multipart.Write把文件的文本流写入一个缓存中,然后调用http的Post方法把缓存传到服务器. package main import ( "bytes" ...

  9. .Net Core之Swagger

    1.项目生成xml 2.添加链接文件,并将属性设值为始终复制 3.添加swagger引用:Swashbuckle.AspNetCore 4.startup.cs配置swargger的xml来源: Co ...

  10. NOIP2018退役祭

    退役感受 在写下这个标题的时候,我的心情是复杂的,无非就是感觉像对一位将要赶往战场的士兵说:"你的战争已经输掉了." 退役了,没有什么好说的.无论再怎么抱怨这题出的真烂也无法改变了 ...