C# Winform中让DataGridView单元格显示图片
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C# Winform中让DataGridView单元格显示图片
private void bind(DateTime st,DateTime et)
{
this.dataGridView1.DataSource = null;
// this.dataGridView1.Refresh();
this.dataGridView1.Columns.Clear();
this.dataGridView1.DataSource =
BusinessUserBLL.GetWaterTicketForConfirm(st, et,
FrmMain.sessionuser.wstationobj.Id);
this.dataGridView1.Columns[0].HeaderText = "开票日期";
this.dataGridView1.Columns[0].Width = 120;
this.dataGridView1.Columns[0].DataPropertyName = "日期";
this.dataGridView1.Columns[1].HeaderText = "水票编号";
this.dataGridView1.Columns[1].DataPropertyName = "水票编号";
this.dataGridView1.Columns[2].HeaderText = "用户名";
this.dataGridView1.Columns[2].Width = 80;
this.dataGridView1.Columns[2].DataPropertyName = "用户名";
for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
{
if (i > 2)
{
this.dataGridView1.Columns[i].Visible = false;
}
}
this.dataGridView1.Rows[0].Selected = false;
DataGridViewImageColumn img = new DataGridViewImageColumn();
img.HeaderText = "是否确认";
img.Width = 80;
this.dataGridView1.Columns.Insert(3, img);
for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
{
if (this.dataGridView1.Rows[i].Cells["确认
"].Value.ToString().ToLower().Trim() == "true") this.dataGridView1[3, i].Value = Image.FromFile("check.gif");
else
this.dataGridView1[3, i].Value = Image.FromFile("feedback.gif");
}
}