DataGridViewImageColumn Imange = newDataGridViewImageColumn();
Imange.HeaderText = “照片”;
Imange.Image = this.pictureBox1.Image;//把PictureBox上的图片赋值给图像列
Imange.ImageLayout = DataGridViewImageCellLayout.Zoom;//设置“照片”列的图像制定布局设定为缩略图
this.dataGridView1.Columns.Add(Imange);//最后添加这
简化写法 为 : this.Column5.ImageLayout = DataGridViewImageCellLayout.Zoom; 填到指定的列里
如果是绑定的数据化的,这个位置的列 定制为 Image类型就可以了。方法为:
public class Testclass
{
public int Id { get; set; }
public string Name { get; set; }
public string ImagePath { get; set; }
public Image GetImage
{
get
{
Image img = null ;
if (File.Exists(ImagePath))
{
img = Image.FromFile(ImagePath);
}
return img;
}
}
}