源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Winform在DataGridView中显示图片

  • 时间:2022-12-11 05:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Winform在DataGridView中显示图片
首先,要添加图片列,绑定数据的时候会触发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如何显示图片一些代码片段,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部