This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, Is there an easy way to filter child nodes? |
|
|
,
|
|
|
Each row in the grid is a PropertyGridRow with a Children property of type PropertyGridBindingView. You can therefore filter child nodes by applying a Filter to the Children.DefaultView collection view. This means there isn't an "easy" way to apply filtering across the entire hierarchy. Let me digress for a moment to explain the reasoning behind this seeming omission. We did consider this but it raises some issues as to the behaviour in the general case: for example, if I have a top-level node named Foo with a child named Bar, and I filter for "name contains 'a'," do we show Foo? If we don't (on the grounds that it doesn't contain 'a,' we can't show Bar, even though this *does* contain 'a'. If we do show Foo, users might be confused that something that should have been filtered out is still displaying. (There are also a couple of implementation reasons to be concerned about that second option: the additional complexity of writing a filter to scan down the hierarchy, and the fact that such a filter would force us to scan all the way down the hierarchy in order to determine whether to show each top-level node; the latter is potentially expensive and introduces complexities around things like cycle detection.) So we decided to leave this up to applications, which would be able to apply application-specific judgment based on their user requirements, their data sets and the type of filtering they were doing. Anyway, back to the question. Given that there's no "easy" way, here's an outline of the "less easy" way. Once you have determined what you want the behaviour to be and coded it up as a Predicate<PropertyGridRow> (including searching down the hierarchy if necessary to keep a parent node visible because you need to display one of its child nodes), it it basically a matter of starting from grid.BindingView and applying the following algorithm recursively: private void ApplyFilter(PropertyGridBindingView bv) If you expect to modify the sets of children after applying the filter, you may also need to hook up CollectionChanged event notifications. Note that this will cause all descendants to load, depth-first. This can have a performance impact for large hierarchies and won't work if there are cycles in the object graph (because then the grid can go infinitely deep). At the moment we don't have a way to apply a filter lazily, which would get around these problems; if that's your scenario then let us know and we'll see what we can do. |
|
|
Thanks for your reply Ivan. I really like your component and expect we will purchase it shortly. David |
|