【发布时间】:2014-10-23 15:18:35
【问题描述】:
如果我有两个对象,即Fruit' andColor`,它们的定义如下:
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 |
+-----+--------+----------+
而不像下面的输出:(注意:N.Color 中的 N 表示对象 Color 的命名空间)
+-----+--------+------------+
| Id | Name | Color |
+-----+--------+------------+
| 10 | Apple | N.Color |
| 20 | Orange | N.Color |
| 30 | Grapes | N.Color |
+-----+--------+------------+
更新 #1:
我在 SO 上找到了类似的帖子 here 并尝试了关于该帖子的一些建议,但它不起作用......
【问题讨论】:
-
你的类
Color中是否有Color类型属性Color,因为那样你会得到输出N.Color,还有为什么你的颜色类中的Name是类型int? -
哦,我的错,我忘了把它改成字符串。我会尽快修改。
-
是的,我的 Fruit 类中有一个 Color 类型的属性
标签: c# winforms mvp architectural-patterns