10

我有一个字段DataGridViewImageColumn,对于字段的每一行,根据条件,我添加不同的图像。任何人都知道我如何在 Windows 窗体中做到这一点?

if (dgvAndon.Rows[e.RowIndex].Cells["urgencyOrder"].ToString() == "1")
{
   //Here I want to add the image in the image property field DataGridViewImageColumn.
}
4

5 回答 5

12
  1. 在属性文件夹下的 Resources.resx 中添加您的图像。(例如 Picture1.jpeg)
  2. DataGridViewImageColumn在你的添加一个DataGridView
  3. 以这种方式添加图像:

    for (int row = 0; row <= [YourDataGridViewName].Rows.Count - 1; row++)
    {
        ((DataGridViewImageCell)gvFiles.Rows[row].Cells[1]).Value = Properties.Resources.Picture1
    }
    
于 2013-06-28T13:39:28.063 回答
3

使用此代码:

        DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
        iconColumn.Name = "AirplaneImage";
        iconColumn.HeaderText = "Airplane Image";
        dataGridView1.Columns.Insert(5, iconColumn);

        for (int row = 0; row < dataGridView1.Rows.Count - 1; row++)
        {
            Bitmap bmp = new Bitmap(Application.StartupPath + "\\Data\\AirPlaneData\\" + dt.Rows[row][4]);
            ((DataGridViewImageCell)dataGridView1.Rows[row].Cells[5]).Value = bmp;
        }
于 2017-03-17T10:19:26.393 回答
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;
     }
    }
于 2013-10-28T10:55:10.650 回答
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);
}
于 2019-07-18T11:53:23.477 回答
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);
于 2020-08-13T12:58:33.547 回答