Winform在DataGridView中顯示圖片。本站提示廣大學習愛好者:(Winform在DataGridView中顯示圖片)文章只能為提供參考,不一定能成為您想要的結果。以下是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若何顯示圖片一些代碼片斷,願望能給年夜家一個參考,也願望年夜家多多支撐。