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

时间:2022-09-02 11:38:02

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. 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.

我想从“详细信息”模式中的视图中过滤掉一些列表视图项,其中包含行和列。创建这样一种机制的最佳选择是什么?我可以从视图中快速删除有问题的项目,保留其他项目,并在不再需要过滤listview项目时将它们放回列表视图中?我应该将它们删除/复制到列表中,并在完成时将其添加回来,还是有更好的方法更有效地执行此操作?列表视图将包含大约100-500个项目。

2 个解决方案

#1


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.

如果没有,我可能会单独存储列表的所有项目,并根据任何上下文要求(如过滤)每次填充控件。迭代列表并移动当前不需要的项的代码可能不必要地复杂化。每次完全重新填充将更容易,并且在计算费用方面不会有太大差异。

#2


This behavior is built in to BindingSources using DataSets in .Net 2.0.

使用.Net 2.0中的DataSet将此行为内置到BindingSources中。

For .Net 3.0+, you can use LINQ.

对于.Net 3.0+,您可以使用LINQ。

#1


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.

如果没有,我可能会单独存储列表的所有项目,并根据任何上下文要求(如过滤)每次填充控件。迭代列表并移动当前不需要的项的代码可能不必要地复杂化。每次完全重新填充将更容易,并且在计算费用方面不会有太大差异。

#2


This behavior is built in to BindingSources using DataSets in .Net 2.0.

使用.Net 2.0中的DataSet将此行为内置到BindingSources中。

For .Net 3.0+, you can use LINQ.

对于.Net 3.0+,您可以使用LINQ。