我想显示> 50000表中的行。这是最好的控制使用方法:DataGrid或一个ListView(详细查看)?这些控件将有更好的表现?
I want to display >50000 rows in a table. Which is the best control to use: a DataGrid or a ListView (in details view)? Which of these controls will have the better performance?
正如汉斯说,在评论原来的问题,他们都将有糟糕的表现,只能由不悦您的用户必将经验超过被显示在同一时间的数据的许多行蛊
As Hans says in a comment to the original question, they're both going to have abysmal performance, surpassed only by the displeasure that your users will surely experience at the insanity of so many lines of data being displayed at the same time.
但如果这是不可避免的在你的应用程序(和您提供的非常的良好的搜索功能),那么你应该认真考虑使用虚拟模式选项,无论哪控制你决定使用。这意味着你必须提供自己的数据管理操作,而不是依靠控制为你做它。它的优点是,事情快得多。由于documentation说:
But if this is unavoidable in your application (and you provide a very good search function), then you should strongly consider using the virtual mode option, regardless of which control you decide to use. This means that you must provide your own data-management operations, rather than relying on the control to do it for you. The advantage is that things are much faster. As the documentation says:
虚拟模式被设计用于数据非常大的商店。当 VirtualMode
属性为true,将创建一个的DataGridView
与行和列的一组号码,然后办理CellValueNeeded事件以填充细胞。虚拟模式需要执行一个基本数据高速缓存来处理人口,编辑和删除基于用户的操作的DataGridView单元组成。有关实现虚拟模式的详细信息,请参阅如何:实现在Windows虚拟模式窗体DataGridView控件。
Virtual mode is designed for use with very large stores of data. When the VirtualMode
property is true, you create a DataGridView
with a set number of rows and columns and then handle the CellValueNeeded
event to populate the cells. Virtual mode requires implementation of an underlying data cache to handle the population, editing, and deletion of DataGridView cells based on actions of the user. For more information about implementing virtual mode, see How to: Implement Virtual Mode in the Windows Forms DataGridView Control.
或者,对于所述ListView控制:
Or, for the ListView
control:
设置 VirtualMode
属性为true放的ListView
进入虚拟模式。在虚拟模式下,正常的Items收集未使用。相反,ListViewItem动态创建的对象为在ListView需要他们。
Setting the VirtualMode
property to true puts the ListView
into virtual mode. In Virtual mode, the normal Items
collection is unused. Instead, ListViewItem
objects are created dynamically as the ListView requires them.
虚拟模式可以在许多情况下是有用的。如果的ListView
对象必须从一个非常大的收藏已经在内存中填充,从而为每个条目的ListViewItem
对象可以是一种浪费。在虚拟模式下,只要求项被创建。在其他情况下,在 ListViewItem的
对象的值,可能需要频繁地重新计算,并且这样做对于整个集合将产生不可接受的性能。在虚拟模式下,仅将所需项目的计算。
Virtual mode can be useful under many circumstances. If a ListView
object must be populated from a very large collection already in memory, creating a ListViewItem
object for each entry can be wasteful. In virtual mode, only the items required are created. In other cases, the values of the ListViewItem
objects may need to be recalculated frequently, and doing this for the whole collection would produce unacceptable performance. In virtual mode, only the required items are calculated.
为了使用虚拟模式,你必须处理的RetrieveVirtualItem事件,这是每次的ListView
要求的项目提出。此事件处理程序应该创建的ListViewItem
对象所属的指定索引处。此外,该VirtualListSize属性的必须设置为虚拟列表的大小
In order to use virtual mode, you must handle the RetrieveVirtualItem
event, which is raised every time the ListView
requires an item. This event handler should create the ListViewItem
object that belongs at the specified index. In addition, the VirtualListSize
property must be set to the size of the virtual list.
办理SearchForVirtualItem事件使搜索虚拟模式。如果不处理该事件时,FindItemWithText和FindNearestItem方法将返回null。
Handling the SearchForVirtualItem
event enables searching in virtual mode. If this event is not handled, the FindItemWithText
and FindNearestItem
methods will return null.
您可以处理CacheVirtualItems为了维持的ListViewItem
对象缓存事件。如果计算或查找创建一个的ListViewItem
对象是昂贵的,保持了高速缓存可以提高性能。
You can handle the CacheVirtualItems
event in order to maintain a cache of ListViewItem
objects. If the calculation or lookup to create a ListViewItem
object is expensive, maintaining a cache can improve performance.
如果在View物业设置为平铺,该值将自动更改为LargeIcon当 VirtualMode
设置为true。
If the View
property is set to Tile, the value will automatically be changed to LargeIcon when VirtualMode
is set to true.
在虚拟模式下,Items收藏已禁用。试图访问它导致的InvalidOperationException.同样是CheckedItems收集和SelectedItems采集。如果你要检索的选择或检查的项目,使用SelectedIndices和CheckedIndices集合吧。
In virtual mode, the Items
collection is disabled. Attempting to access it results in an InvalidOperationException
. The same is true of the CheckedItems
collection and the SelectedItems
collection. If you want to retrieve the selected or checked items, use the SelectedIndices
and CheckedIndices
collections instead.