如果我有两个对象,即Fruit' and
Color ,它们的定义如下:
public class Fruit
{
public int FruitId { get; set; }
public string Name { get; set; }
public Color Color { get; set; }
}
public class Color
{
public int ColorId { get; set; }
public string Name { get; set; }
}
如何将集合绑定Fruit
(e.g. List<Fruit>)
到 DataGridView?结果输出将类似于以下内容:
+-----+--------+----------+
| Id | Name | Color |
+-----+--------+----------+
| 10 | Apple | Red |
| 20 | Orange | Orange |
| 30 | Grapes | Violet |
+-----+--------+----------+
并且不喜欢下面的输出:(注意:NN.Color
表示对象颜色的命名空间)
+-----+--------+------------+
| Id | Name | Color |
+-----+--------+------------+
| 10 | Apple | N.Color |
| 20 | Orange | N.Color |
| 30 | Grapes | N.Color |
+-----+--------+------------+
更新 #1:我在 SO 上找到了
一个类似的帖子,并尝试了该帖子的一些建议,但它不起作用......