111,093
社区成员




DataGridViewImageColumn image = new DataGridViewImageColumn();
image.ImageLayout = DataGridViewImageCellLayout.Zoom;
image.HeaderText = "图片描述";
image.Name = "图片描述";
image.Width = 80;
this.dgview_Lesson.Columns.Add(image);
for (int i = 0; i < this.dgview_Lesson.Rows.Count; i++)
{
L_Lesson Info = Lessonlist[i] as L_Lesson;
if (System.IO.File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "\\Lesson\\" +
Path.GetFileName(Info._Image.ToString())))
{
this.dgview_Lesson["图片描述", i].Value = Image.FromFile(Path.GetDirectoryName(
Application.ExecutablePath) + "\\Lesson\\" + Path.GetFileName(Info._Image.ToString()));
}
}
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
DataGridViewImageCell imgCell = dataGridView1.Rows[i].Cells[0] as DataGridViewImageCell;
imgCell.Value = Image.FromFile(dt.Rows[i]["imageurl"].ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1["d", 0].Value = new Bitmap(@"C:\Users\xiebin\Desktop\common\1.jpg");
}
DataGridViewImageColumn image = new DataGridViewImageColumn();
image.ImageLayout = DataGridViewImageCellLayout.Zoom;
image.HeaderText = "图片描述";
image.Name = "图片描述";
//把image和数据源属性绑定起来
image.DataPropertyName="_Image";
image.Width = 80;
this.dgview_Lesson.Columns.Add(image);
//因为原始数据源不是二进制流,只是string,所以需要在显示的处理转换,此处定制cellFormart显示转换事件
this.dgview_Lesson.CellFormatting += new DataGridViewCellFormattingEventHandler(dgview_Lesson_CellFormatting);
void dgview_Lesson_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dgview_Lesson.Columns[e.ColumnIndex].Name == "图片描述")
{
if (e.Value != null)
{
//处理你自己的过程,初始进入e.value是string,返回是image
e.value=Image.FromFile(e.value);
}
}
}