【问题标题】:How do you add an image to a single specific cell in a DataGridView?如何将图像添加到 DataGridView 中的单个特定单元格?
【发布时间】:2016-08-08 16:39:35
【问题描述】:

使用 C# 和 Visual Studio,我有一个带有 2 列的 DataGridView。对于每一行,第一列将显示文本。对于除一个特定行之外的每一行,第二列将显示文本。在第二列的一个特定单元格中,我需要显示一张图片。

例如:

Row[0].Cell[0] = "test"  Row [0].Cell[1] = "test"
Row[1].Cell[0] = "test"  Row [1].Cell[1] = "test"
Row[2].Cell[0] = "test"  Row [2].Cell[1] = need to display an image here
Row[3].Cell[0] = "test"  Row [3].Cell[1] = "test"

【问题讨论】:

    标签: c# image datagridview cell


    【解决方案1】:

    有不止一种方法可以做到这一点,但这里有一个简单的示例,它将设置一个单元格来显示图像:

        Bitmap bmp = (Bitmap) Bitmap.FromFile(someimagefile);
    
        DataGridViewImageCell iCell = new DataGridViewImageCell();
        iCell.Value = bmp;
        dataGridView1[1, 2] = iCell;
    

    当然,任何其他图像源也可以使用..

    如果您更改位图,请尽量不要泄漏它们..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-09
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 2023-01-20
      • 2014-06-08
      • 1970-01-01
      • 2013-05-27
      相关资源
      最近更新 更多