首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在我的DataGridViewImageColumn中添加镜像?

如何在我的DataGridViewImageColumn中添加镜像?
EN

Stack Overflow用户
提问于 2013-06-28 21:35:26
回答 5查看 40.5K关注 0票数 10

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

代码语言:javascript
复制
if (dgvAndon.Rows[e.RowIndex].Cells["urgencyOrder"].ToString() == "1")
{
   //Here I want to add the image in the image property field DataGridViewImageColumn.
}
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-06-28 21:39:28

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

for (int row = 0;row <= YourDataGridViewName.Rows.Count - 1;row++) { ((DataGridViewImageCell)gvFiles.Rowsrow.Cells1).Value = Properties.Resources.Picture1 }

票数 12
EN

Stack Overflow用户

发布于 2017-03-17 18:19:26

使用以下代码:

代码语言:javascript
复制
        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;
        }
票数 3
EN

Stack Overflow用户

发布于 2013-10-28 18:55:11

使用此代码

代码语言:javascript
复制
 protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs args)
    {
     if(args.Row.RowType == DataControlRowType.DataRow)
     {
      Image img = (Image) e.Row.FindControl("Image1");
      img.ImageUrl = setImageURLHere;
     }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17365965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档