Winform在DataGridView中显示图片
作者:秦风 时间:2023-06-26 21:02:48
首先,要添加图片列,绑定数据的时候会触发CellFormatting事件,在事件中取出图片路径,读取图片赋值给当前单元格。
private void dataGridview1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridview1.Columns[e.ColumnIndex].Name.Equals("Image"))
{
string path = e.Value.ToString();
e.Value = GetImage(path);
}
}
public System.Drawing.Image GetImage(string path)
{
System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);
System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
fs.Close();
return result;
}
标签:DataGridView
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中一个线程执行死循环有什么后果
2022-05-24 00:28:35
基于集合的子集与集合的全排列的相关问题
2023-09-23 07:03:46
listview控件实现点击列表头进行listview排序示例分享
2023-06-06 18:00:39
轻松掌握Java建造者模式
2023-11-06 15:24:38
C语言数据结构之单链表与双链表的增删改查操作实现
2023-01-24 07:27:35
![](https://img.aspxhome.com/file/2023/1/117781_0s.jpg)
C#加密知识整合 (AES,MD5,RSA,SHA256)
2023-07-19 09:09:13
C# 中 System.Index 结构体和 Hat 运算符(^)的使用示例
2023-02-27 11:40:23
IDEA SpringBoot项目配置热更新的步骤详解(无需每次手动重启服务器)
2023-11-12 00:22:41
![](https://img.aspxhome.com/file/2023/9/59659_0s.jpg)
Android开发使用Message对象分发必备知识点详解
2022-02-08 21:32:49
![](https://img.aspxhome.com/file/2023/4/105974_0s.jpg)
c#与WMI使用技巧集第1/2页
2022-03-16 05:16:01
Java使用synchronized修饰方法来同步线程的实例演示
2022-11-29 18:33:29
Android 实例开发基于ArcSoft实现人脸识别
2022-01-01 16:34:06
![](https://img.aspxhome.com/file/2023/1/137321_0s.jpg)
C# Winform消息通知系统托盘气泡提示框ToolTip控件
2023-01-13 23:31:02
![](https://img.aspxhome.com/file/2023/5/68075_0s.jpg)
spring boot结合Redis实现工具类的方法示例
2023-05-12 09:47:46
浅谈Java内存区域划分和内存分配策略
2023-08-11 18:52:49
![](https://img.aspxhome.com/file/2023/6/58146_0s.png)
解析JDK14中的java tools简介
2023-04-18 10:28:37
c# 进程之间的线程同步
2023-07-05 06:34:23
C#中委托、事件和回调的使用及说明
2023-08-13 01:00:24
![](https://img.aspxhome.com/file/2023/6/82136_0s.png)
Java应用层协议WebSocket实现消息推送
2022-05-09 07:26:29
![](https://img.aspxhome.com/file/2023/0/94370_0s.png)
一篇文章带你深入了解javaIO基础
2022-10-22 21:43:05
![](https://img.aspxhome.com/file/2023/6/128926_0s.png)