Winform在DataGridView中显示图片
首先,要添加图片列,绑定数据的时候会触发CellFormatting事件,在事件中取出图片路径,读取图片赋值给当前单元格。
privatevoiddataGridview1_CellFormatting(objectsender,DataGridViewCellFormattingEventArgse)
{
if(dataGridview1.Columns[e.ColumnIndex].Name.Equals("Image"))
{
stringpath=e.Value.ToString();
e.Value=GetImage(path);
}
}
publicSystem.Drawing.ImageGetImage(stringpath)
{
System.IO.FileStreamfs=newSystem.IO.FileStream(path,System.IO.FileMode.Open);
System.Drawing.Imageresult=System.Drawing.Image.FromStream(fs);
fs.Close();
returnresult;
}
以上就是DataGridView如何显示图片一些代码片段,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短