简体   繁体   English

C#:为ListView项目实现“过滤器”机制的最佳方法是什么?

[英]C#: What is the best way to implement a 'filter' mechanism for ListView Items?

C#: What is the best way to implement a 'filter' mechanism for ListView Items? C#:为ListView项目实现“过滤器”机制的最佳方法是什么?

I want to filter out some listview items from view in 'details' mode where it contains rows and columns. 我想从包含行和列的“详细信息”模式下从视图中过滤掉一些listview项目。 What would be the best option to create such a mechanism where I could rapidly remove the items in question from view, leaving the others intact, and putting them back into the listview when there is no more need to filter out listview items? 创建这样一种机制的最佳选择是什么,即当我不再需要过滤掉列表视图项时,可以快速从视图中删除有问题的项目,保持其他列表不变,然后将它们放回列表视图中? Should I remove/copy them to a List and just and add them back when done or would there be a better method of doing this more effeciently? 我应该将它们删除/复制到列表中,然后在完成后再添加回去,还是有更好的方法来更有效地执行此操作? The listview will be handeling about 100-500 items. 列表视图将处理约100-500个项目。

This behavior is built in to BindingSources using DataSets in .Net 2.0. 此行为是使用.Net 2.0中的数据集内置到BindingSources中的。

For .Net 3.0+, you can use LINQ. 对于.Net 3.0+,可以使用LINQ。

If you are working with a databound control you will have this facility within the binding framework. 如果您正在使用数据绑定控件,则绑定框架中将具有此功能。

If not, I would probably store all the items for the list separately and populate the control in full each time, based on any contextual requirements such as filtering. 如果没有,我可能会单独存储列表的所有项目,并根据任何上下文要求(例如过滤)每次都完全填充控件。 The code to iterate through the list and move items not required at present is probably unnecessarily complicated. 遍历列表和移动当前不需要的项目的代码可能不必要地变得复杂。 A full repopulate each time will be easier and won't differ much in terms of computational expense. 每次进行完整的填充将更加容易,并且在计算开销方面不会有太大差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM