问题
I tried to filter TreeListView
using delegates like in the documentation: Filtering ObjectListView
So it goes like this:
this.myTree.ModelFilter = new ModelFilter(delegate(object x) {
return (((MyTreeNode)x).Type == type); // this code doesn't work, why ?
});
As result, myTree
should include all nodes with .Type
property is equal to type
, in my case there are no nodes in the tree, why ???.
But, if I set .Type
property to type of the root node, then it will be only one root node in the tree, so in this case it works.
ETA: Why filtering with the above code doesn't work ?
回答1:
From your question, it's not entirely clear what your TreeListView
structure looks like. But it may have something to do with the fact that you want to filter child items that haven't been fetched yet (unexpanded nodes)?
From the tutorial link you already referenced:
Filtering and TreeListViews
Filtering and TreeListViews interact in a predictable but perhaps unexpected fashion.
Filtering considers only rows that are currently exposed (that is, all their ancestorss are expanded).
Within those rows, rows will be included by the filtering process if they or any of their descendents will be included by the filtering. (Yes, this is recursive). If a bottom level child matches the filtering criteria, then all its ancestors will be considered to have matched as well and thus will be shown in the control.
In the majority of situations, this gives the most predictable and useful visual results.
来源:https://stackoverflow.com/questions/15472066/how-to-filter-objectlistviews-treelistview