如何在winform的datagridview的列image列中显示图象
1个回答
展开全部
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;
}
使用DataGridViewImageColumn
DataGridViewImageColumn column = new DataGridViewImageColumn();
dataGridView1.Columns.Add(column);
column.HeaderText = "图片";
column.Image = System.Drawing.Image.FromFile("路径");
((DataGridViewImageCell)this.dataGridView1.Rows[e.RowIndex].Cells[ "图片列"]).Value = "路经 "
{
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;
}
使用DataGridViewImageColumn
DataGridViewImageColumn column = new DataGridViewImageColumn();
dataGridView1.Columns.Add(column);
column.HeaderText = "图片";
column.Image = System.Drawing.Image.FromFile("路径");
((DataGridViewImageCell)this.dataGridView1.Rows[e.RowIndex].Cells[ "图片列"]).Value = "路经 "
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询