在WinForms列表框/列表视图控件中显示大量字符串 [英] Displaying a large number of strings in WinForms listbox/listview controls

查看:74
本文介绍了在WinForms列表框/列表视图控件中显示大量字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WinForms UI包含一个带有两个标签页的标签控件.在一个选项卡上,我需要以最多允许我的用户在列表中添加,编辑和删除字符串的方式显示最多100,000个字符串的列表.在第二个选项卡上,我需要显示第一个选项卡中字符串的只读"副本.我还需要第二个选项卡上的控件,这些控件允许用户将字符串从只读"列表复制到第二个不相关的列表中.

My WinForms UI contains a tab control with two tab pages. On one tab, I need to display a list of up to 100,000 strings in a manner that allows my users to add, edit and delete strings in the list. On the second tab, I need to display a "read-only" copy of the strings from the first tab. I also need controls on the second tab that allow the user to copy strings from the "read-only" list into a second unrelated list.

我目前在数组中有100k字符串,我的第一个念头是使用列表框显示它们.我可以遍历数组并将字符串分别添加到第一个选项卡上的列表框中.如果我使用SuspendLayout()和BeginUpdate(),则大约需要1.5秒才能显示.不幸的是,当我向列表框中添加超过65k项时,存在垂直滚动条问题(显然,这是Vista左右引入的列表框控件中的错误).由于字符串数据未绑定到列表框,因此我基本上是将相同的整个数据集添加到第二个选项卡上的另一个列表框.现在,如果我启动我的应用程序,请等待将字符串添加到列表框中,然后尝试选择第二个选项卡,等待第二个选项卡响应时,性能将非常缓慢.我假设这与列表框中的数据量有关.无论如何,一旦第二个标签页响应,我就可以在两个标签页之间进行切换,而所花费的时间要少得多.

I currently have the 100k strings in an array and my first thought was to use a listbox to display them. I can loop through the array and individually add the strings to a listbox on the first tab. That takes about 1.5 seconds to display if I use SuspendLayout() and BeginUpdate(). Unfortunately, there are vertical scrollbar issues when I add more than ~65k items to a listbox (apparently this is a bug in the listbox control that was introduced around the time of Vista). Since the string data is not bound to the listbox, I'm basically adding the same entire data set to another listbox on my second tab. Now if I launch my app, wait for the strings to be added to the listboxes and then try to select the second tab, the performance is very slow waiting for the second tab to become responsive. I'm assuming this is related to the volume of data in the listboxes. Anyway, once the second tab becomes responsive, I can switch between the two tab pages with much less of a delay.

作为测试,我尝试将两个列表框都绑定到数组,但是从性能的角度来看并没有任何区别.无论如何,滚动错误可能会使列表框成为我无法使用的选项.因此,我尝试了使用单个隐藏列标题的列表模式下的listview控件.当我将字符串数据添加为单独的ListViewItems时,性能没有太大不同.我打算尝试将两个listview控件绑定到我的数组,但是listview控件似乎不支持设计时数据绑定,并且我不确定如果自己尝试实现它,将不会有很大的不同.

As a test, I tried binding both listboxes to the array but it didn't make any difference from a performance standpoint. And the scrolling bug is probably going to make the listbox an unusable option for me anyway. So then I tried the listview control in list mode with a single hidden column header. The performance isn't much different when I add the string data as individual ListViewItems. I was going to try binding two listview controls to my array but it looks like the listview control doesn't support design-time data binding and I'm not sure that it would make much difference if I were to try to implement it myself.

我知道100,000个字符串(最大)是供用户处理的大量数据,但这是要求用户能够查看应用程序中的所有字符串数据(最坏的情况是我的质量检查的第一件事团队将开始进行测试!).是否还有另一种控件可用于这种数据量和我需要的功能?还是我只是想解决所有这些错误?

I know 100,000 strings (max) is a lot of data for a user to process but it's a requirement that the use be able to see all of the string data in the application (and the worst case is the first thing my QA team will start testing with!). Is there another control that would lend itself to this volume of data and the functionality that I need? Or am I just going about this all wrong?

推荐答案

我认为您不会通过一次为用户提供50个以上的字符串来帮助用户.使用DataGridView,您可以按需加载,这更适合于此.请参阅 VirtualMode .否则,您可以在用户输入时手动将项目加载到列表框,这更好.尝试说服这方面的客户,一次拥有10万个字符串只会弊大于利.

I dont think you will ever help the user by providing more than 50 strings at a time for the user. With a DataGridView you could load on demand which is better suited for this. See VirtualMode. Or else you could load items to listbox manually on user input, which is way better. Try to convince the customer on that front that it will only do more harm than good to have 100k strings at a time.

我确实认为DataGridViews太多了,无法显示简单的字符串,但为您提供了将来提供更多功能(如更多列等)的灵活性.至于如何将大量数据填充到gridiview中,请进行搜索,上面有很多线程.这是两个很好的入门者

I do think DataGridViews will be too much to display simple strings, but provides you the flexibility to provide more features in future (like more columns etc). As to how to populate that large amount of data to a gridiview, do a search, there are plenty of threads on it. Here are two good starters

http://www.codeproject .com/Articles/38735/Load-a-billion-rows-in-a-DataGridView

是什么更好地使用:用于显示大量数据的DataGrid或ListView?

正如我所说,最好的选择是重新考虑设计.

这篇关于在WinForms列表框/列表视图控件中显示大量字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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