使用 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"
最佳答案
有不止一种方法可以做到这一点,但这里有一个简单的示例,它将设置一个单元格来显示图像:
Bitmap bmp = (Bitmap) Bitmap.FromFile(someimagefile);
DataGridViewImageCell iCell = new DataGridViewImageCell();
iCell.Value = bmp;
dataGridView1[1, 2] = iCell;
当然任何其他图像源也可以工作..
如果更改位图,请尽量不要泄漏它们。
关于c# - 如何将图像添加到 DataGridView 中的单个特定单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38834443/