【发布时间】:2011-01-14 13:51:08
【问题描述】:
下面的两个代码 sn-ps 填充了一个 BindingSource,稍后将其分配给 一个 DataGridView.DataSource。
当使用具体类 QuotesTool.LineItem(第一个 sn-p)时,网格不会显示适当的数据:
BindingSource lineList = new BindingSource();
foreach (XElement y in _lines.Elements())
{
lineList.Add(new QuotesTool.LineItem(
y.Element("Vendor").Value,
y.Element("Model").Value,
y.Element("Selling_Unit").Value,
y.Element("Net_Price").Value,
y.Element("Spec").Value
));
}
但是,如果使用匿名类型,则网格显示数据正常:
foreach (XElement y in _lines.Elements())
{
lineList.Add(
new {
vendor = y.Element("Vendor").Value,
Model = y.Element("Model").Value,
UOM = y.Element("Selling_Unit").Value,
Price = y.Element("Net_Price").Value,
Description = y.Element("Spec").Value
});
}
任何想法将不胜感激。谢谢。
【问题讨论】:
标签: c# datagridview anonymous concrete