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. mysql用户的增删与密码丢失问题

    为root用户设置初始密码 mysqladmin -u root password 密码(单实例) mysqladmin -u root password 密码 -S /data/3306/mysql ...

  2. nodejs 开发,手把手开始第一个服务器程序(原生)

    此文章为原生 nodejs  ,仅做学习使用 想学习 express 和 koa2 的小伙伴请绕路 此文章适合有HTML 和css .js 基础的小伙伴看哦 如果能帮到你,荣幸之至 文章纯手打,如有纰 ...

  3. Windows下配置Jenkins 实现自动发布maven项目至tomcat(svn+maven+tomcat)

    Jenkins安装完成之后,需要我们对其配置,然后才可以实现自动部署项目. 前提 防火墙开放tomcat的8080端口 Linux(CentOS):firewall-cmd --zone=public ...

  4. Python3基础 response.info 服务器返回的header信息

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. eMMC ext4综述【转】

    本文转载自:https://blog.csdn.net/lieye_leaves/article/details/78214410 eMMC ext4综述一.系统的引导启动1.1系统的引导启动http ...

  6. eMMC分区详解【转】

    本文转载自:https://blog.csdn.net/wxh0000mm/article/details/77864002 转自:http://blog.csdn.net/junzhang1122/ ...

  7. linux内核中的hisi_sas是什么?

    答: 是一个HISILICON SAS 控制器驱动(HISILICON SAS controller driver)

  8. 为什么不能用drop function add 去删除函数? 因为不能使用 mysql中的保留字!

    mysql中有很多的 保留字, 也叫关键字, 你在使用 数据库中的任何东西, 都最好是 避开这些关键字/保留字, 包括 数据库名, 表名, 字段名, 函数名, 存储过程名. 这些关键字包括: mysq ...

  9. 批量Excel数据导入Oracle数据库 导入excel错误:外部表不是预期的格式 解决方案

    在asp.net网站中导出Excel文件后,再把文件导入到数据库中. 读取Excel文件时,打开连接出错. 错误为:外部表不是预期的格式 解决:检查了一下,导出的Excel是标准文件不是html,没错 ...

  10. 理解 Redis(2) - 手把手教你理清 Redis 安装全过程

    Redis 官网 https://redis.io/ 之前学习 Redis 学了好多次, 下载安装也都按照教程或官网文档弄过, 但是对于安装过程一直有点迷糊, 感觉稀里糊涂地就好了, 就可以用了. 这 ...