How to filter objectlistview's TreeListView?

笑着哭i 提交于 2019-12-08 12:25:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!