在大型列表视图中使用C#轻松选择所有内容,而无需单独循环遍历每个元素 [英] Easy select all with C# in a big listview without looping through each element separately

查看:104
本文介绍了在大型列表视图中使用C#轻松选择所有内容,而无需单独循环遍历每个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚如何以编程方式选择巨大列表视图中的所有项目。看起来它应该相对容易,比如ListView.SelectAll()或ListView.Items.SelectAll(),但似乎并非如此。我没有找到全选命令。 STRG + A也不起作用,因此我无法调用它。

任何更好的想法,而不是我试过的所有项目的闪烁缓慢循环?



注意:我为此寻找一个inbuild命令,我可能忽略了仪式功能。



我尝试了什么:



我尝试使用foreach循环遍历每个元素,并分别为每个元素设置属性。它没有完全运行,listView闪烁得很糟糕,需要花费很长时间才能选择50000个元素。我在互联网上发现了一些类似的问题,但没有提供答案。我寻求一个比我的解决方案更好的答案,一个inbuild命令或类似于纯C#的东西。有人知道命令吗?

VB6有一个SelectAll属性,它在一秒钟内选择了多达100K的元素。我需要做些什么才能在我的C#程序中获得此功能?

I can't figure out how to programmatically select all items in a huge listview. It seems like it should be relatively easy, like "ListView.SelectAll()" or "ListView.Items.SelectAll()", but that doesn't appear to be the case. I do not find the "select all" command. STRG+A does not work either and I can't call it therefore.
Any better ideas than a flickering slow loop through all the items which I tried?

Note: I seek an inbuild command for this, I might have overlooked the rite function.

What I have tried:

I tried to loop through each element with foreach loop and set the property for each element separatly. it wasn't working fully, the listView flickered horrible and it took ages for 50000 elements to be selected. I found some similar questions in the internet, but no answers provided. I seek a better answer than my solution, an inbuild command or something alike as pure C#. Does somebody know a command?
VB6 had a "SelectAll" property and it selected up to 100K elements in a second. What I have to do to get this functionality in my C# program?

推荐答案

首先,我要说,如果你要在ListView中加载50000多个项目,你有严重的设计问题。您可能需要考虑某种分页。



好​​的,所以,尝试将集合中的每个项目添加到listView的SelectItem集合中。有点像



foreach(myItems中的var项目)

{

myListView.SelectedItems.Add(item);

}
First, I have to say, if you're loading 50000+ items into a ListView, you have serious design issues. You might want to consider some kind of paging.

Ok, so, try adding each item in your collection to the listView's SelectItem collection.. Something like

foreach(var item in myItems)
{
myListView.SelectedItems.Add(item);
}


这篇关于在大型列表视图中使用C#轻松选择所有内容,而无需单独循环遍历每个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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