更快地选择列表视图中的所有项目 [英] select all items in listview faster

查看:77
本文介绍了更快地选择列表视图中的所有项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何选择列表视图中的所有项目而不会循环?
我大约有30,000件商品,要花很长时间才能选择.

有人可以帮我使用API​​吗?

感谢

How do I select all items in listview without looping?
I have about 30,000 items, and its taking long time to select.

Can anyone help me with API to use?

thanks

推荐答案

不用管选择:填充需要多长时间? :wtf:

任何用户界面中的30,000个项目都太多了:您的贫困用户需要多长时间才能真正找到他们想要的项目?

基本上只有选项:不选择,全部选择.他们没有时间或意愿去做其他事情.

更改您的界面!对其进行分页,搜索,过滤.但是,不要一次向用户展示一百多个左右的物品!
Never mind the select: how long does it take to fill? :wtf:

30,000 items in any user interface is too many: how long is it going to take you poor user to actually find the one(s) they want?

There only options are basically: select none, select all. They won''t have the time or inclination to do anything else.

Change your interface! Page it, search it, filter it. But don''t present the user with more that a hundred or so items at a time!


实际上花费了这么多时间?是您自己的循环本身(我确实相信30000次迭代不会持续那么长时间),还是有其他动作在减慢该过程?您可以尝试禁用事件处理程序(ItemSelectionChanged等,所有这些可能由选择触发),或者在选择之前和之后调用SuspendLayout()/ResumeLayout()方法.另外,如果您确实需要处理30000个项目,请考虑在虚拟模式下使用listview

禁用事件处理程序很容易:例如,您的listview listView1上确实有ItemSelectionChanged处理程序listView1_SelectedIndexChanged.然后选择逻辑应如下所示:

What actually is taking so much time? Is it your loop itself (I do believe 30000 iterations last not that long) or are there additional actions slowing the process? You could try to disable event handlers (ItemSelectionChanged and the like, all that may be triggered by selection) or call SuspendLayout()/ResumeLayout() methods before and after selection. Also, if you really have to deal with 30000 items, consider using listview in virtual mode

Disabling event handlers is easy: for example, you do have ItemSelectionChanged handler, listView1_SelectedIndexChanged on your listview, listView1. Then selection logic should look like that:

listView1.SelectedIndexChanged-=listView1_SelectedIndexChanged;

try
{
 // selection loop
}
finally
{
  listView1.SelectedIndexChanged+=new EventHandler(listView1_SelectedIndexChanged);
}



try/catch块不是必需的,它只是为了确保事件处理程序无论在什么情况下都可以恢复,即使在循环异常之后也可以添加.如果有更多处理程序,例如ItemSelectionChanged,则只需以相同的方式禁用并恢复它们即可.

暂停布局事件也很简单.改进先前的代码块:



Try/catch block is not necessary, it''s added simply to ensure event handler will be restored no matter what, even after exception in loop. If there are more handlers, ItemSelectionChanged, for example, just disable and restore them in the same manner.

Working with layout events suspending is simple as well. Improving previous block of code:

listView1.SelectedIndexChanged-=listView1_SelectedIndexChanged;
listView1.SuspendLayout();

try
{
 // selection loop
}
finally
{
  listView1.SelectedIndexChanged+=new EventHandler(listView1_SelectedIndexChanged);
  listView1.ResumeLayout();
}



最后,将listview置于虚拟模式下甚至不需要代码:).您可以通过属性编辑器"将VirtualMode属性设置为 true (默认情况下为 false )来执行此操作.但是,以这种方式使用listview更加困难:您必须实现RetrieveVirtualItem事件处理程序并提供VirtualListSize属性;您也不能使用Items/SelectedItems集合.还有其他限制(请参见此处),因此您应该自己决定虚拟模式是否适合您的项目



Finally, placing listview in virtual mode doesn''t even require code :). You can do it from Property Editor, setting VirtualMode property to true (by default it''s false). Working with listview this way is harder, though: you have to implement RetrieveVirtualItem event handler and provide VirtualListSize property; also you cannot use Items/SelectedItems collections. There are other limitations as well (see here), so you should decide yourself whether virtual mode suits your project


查看更容易使用ListView [ ^ ].

它具有一个称为FastObjectListView的ListView,可以在不到0.1秒的时间内建立10,000个对象的列表.
Check out A Much Easier to Use ListView[^].

It has a ListView called FastObjectListView that can build a list of 10,000 objects in less than 0.1 seconds.


这篇关于更快地选择列表视图中的所有项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆