【发布时间】:2012-09-27 08:04:49
【问题描述】:
如何从 wpf datagrid 中获取项目数据:
商品值为{ ProductId = 1, Name = "fruit", Quantity = 1, Price = 100.0 },类型为匿名类型。
代码:
foreach (var item in this.dgProductList.Items)
已编辑
这就是我添加行的方式:
this.dgProductList.Items.Add(new { ProductId = product.ProductId, Name = product.Name, Quantity = 1, Price = product.Price });
【问题讨论】:
-
你试过item.ProductId, item.Name, item.Quantity, item.Price吗?不使用 wpf 对我来说才有意义。
-
如何将您的集合绑定到数据网格?你能发布更多代码吗?
-
只需将您的 datagrids itemssource 属性绑定到 Product Collection 并使用此集合执行所有操作、查询、添加、删除...它更简单、更简洁,您不必在如何访问网格中的项目...