我有一个字段DataGridViewImageColumn
,对于字段的每一行,根据条件,我添加了一个不同的图像。任何人都知道如何在Windows窗体中执行此操作?
if (dgvAndon.Rows[e.RowIndex].Cells["urgencyOrder"].ToString() == "1")
{
//Here I want to add the image in the image property field DataGridViewImageColumn.
}
答案 0 :(得分:8)
DataGridViewImageColumn
DataGridView
以这种方式添加图片:
for (int row = 0; row <= [YourDataGridViewName].Rows.Count - 1; row++)
{
((DataGridViewImageCell)gvFiles.Rows[row].Cells[1]).Value = Properties.Resources.Picture1
}
答案 1 :(得分:2)
使用此代码:
The program '[11632] Kiosk2.vshost.exe' has exited with code 0 (0x0).
答案 2 :(得分:0)
使用此代码
protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs args)
{
if(args.Row.RowType == DataControlRowType.DataRow)
{
Image img = (Image) e.Row.FindControl("Image1");
img.ImageUrl = setImageURLHere;
}
}
答案 3 :(得分:0)
string FileName = null;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.RestoreDirectory = true;
openFileDialog.Filter = "All picture files (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
FileName = openFileDialog.FileName;
//pictureBox2.Image = Image.FromFile(FileName);
}
答案 4 :(得分:0)
在您的项目中将图像添加为资源,然后应用下面的代码
DataGridViewImageColumn btnDel = new DataGridViewImageColumn();
btnDel.Name = "DelCourrier";
btnDel.HeaderText = "";
btnDel.Image = Properties.Resources.delete;// delete is the name of the image added as ressource
dataGridView1.Columns.Add(btnDel);