C# 如何将图像添加到DataGridView中的单个特定单元格?

C# 如何将图像添加到DataGridView中的单个特定单元格?,c#,image,datagridview,cell,C#,Image,Datagridview,Cell,使用C#和visualstudio,我有一个带有两列的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] =

使用C#和visualstudio,我有一个带有两列的
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"

方法不止一种,但下面是一个简单的示例,它将设置一个单元格来显示图像:

    Bitmap bmp = (Bitmap) Bitmap.FromFile(someimagefile);

    DataGridViewImageCell iCell = new DataGridViewImageCell();
    iCell.Value = bmp;
    dataGridView1[1, 2] = iCell;
当然,任何其他图像源也可以

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