根据源更新刷新 HiearachicalData?
我有一个 ArrayCollection,我们称之为“Items”。它本质上是分层数据的平面集合(每个项目都有 Parent
和 Children
属性)。我想要一个 AdvancedDataGrid
以分层形式显示数据,所以本质上我可以这样做,它会显示得很好:
// Note: RootItems would be an ArrayCollection that is updated so only the
// top level items are within (item.Parent == null).
var hd:HierarchicalData = new HierarchicalData(model.RootItems);
var hcv:HierarchicalCollectionView = new HierarchicalCollectionView(hd);
myDataGrid.dataProvider = hdc;
这有效,但我希望能够在 myDataGrid< 中看到更新/code> 当
Items
集合更新时(因为 RootItems
不会获取任何子项的更新,只会获取顶级任务的更新)。有什么简单的方法可以做到这一点吗?我猜我必须创建一个扩展 HierarchicalData
的类,并在 Items
更改时以某种方式发出警报,但这听起来会非常慢。预先感谢您提供的任何帮助!
I have an ArrayCollection
we'll call "Items". It is essentially a flat collection of hierarchical data (each item has Parent
and Children
properties). I want an AdvancedDataGrid
to display the data in hierarchical form, so essentially I could just do this and it would display fine:
// Note: RootItems would be an ArrayCollection that is updated so only the
// top level items are within (item.Parent == null).
var hd:HierarchicalData = new HierarchicalData(model.RootItems);
var hcv:HierarchicalCollectionView = new HierarchicalCollectionView(hd);
myDataGrid.dataProvider = hdc;
This works, but I want to be able to see updates in myDataGrid
when the Items
collection is updated (since RootItems
won't pick up updates to any children, only the top level tasks). Is there any easy way to do this? I'm guessing I'll have to create a class that extends HierarchicalData
and somehow alert it when Items
changes, but that sounds like it'll be pretty slow. Thanks in advance for any help you can provide!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两种选择来解决这个问题。您可以创建自己的
IHierarchicalData
实现(它不必扩展HierarchicalData
,在这种特殊情况下,不会有太多可以重用的代码),或者您进行更改稍微处理数据的方式,使其适合标准用例:然后您可以在 ADG 中使用
hcv
作为dataProvider
并使用其方法来添加和删除项目。每当您添加、删除或更新项目时,ADG 都会刷新。我建议您按照标准方式进行操作,除非那确实不可能。
You have two options to solve this problem. Either you create your own implementation of
IHierarchicalData
(it doesn't have to extendHierarchicalData
and in this particular case there won't be much code you can reuse) or you change the way you handle your data a little bit so that it fits into the standard use case:Then you can use
hcv
asdataProvider
in your ADG and use its methods to add and remove items. The ADG will refresh whenever you add, remove or update an item.I suggest you do it the standard way unless that's really not possible.