手机
当前位置:查字典教程网 >编程开发 >C#教程 >Winform在DataGridView中显示图片
Winform在DataGridView中显示图片
摘要:首先,要添加图片列,绑定数据的时候会触发CellFormatting事件,在事件中取出图片路径,读取图片赋值给当前单元格。privatevo...

首先,要添加图片列,绑定数据的时候会触发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如何显示图片一些代码片段,希望能给大家一个参考,也希望大家多多支持查字典教程网。

【Winform在DataGridView中显示图片】相关文章:

winform调用javascript的小例子

c#.NET中日志信息写入Windows日志中解决方案

C# Winform 禁止用户调整ListView的列宽

C#常用正则大全分享

解析C#中的ref和out参数

gridview 显示图片的实例代码

Repeater控件绑定的三种方式

C#难点逐个击破(3):params数组参数

.Net Winform开发笔记(一)

WinForm中DataGridView添加,删除,修改操作具体方法

精品推荐
分类导航