问题描述
我想在表格中显示> 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.
但是如果这在您的应用程序中是不可避免的(并且您提供了 良好的搜索功能),那么您应该强烈地考虑使用虚拟模式选项,无论您决定使用哪种控件。这意味着您必须提供自己的数据管理操作,而不是依靠控件为您执行。优点是事情要快得多。由于说:
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:
或者,对于:
Or, for the ListView
control:
虚拟模式在许多情况下都是有用的。如果一个 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.
为了使用虚拟模式,您必须处理,这是每个时间 ListView
需要一个项目。该事件处理程序应该创建属于指定索引的 ListViewItem
对象。另外,必须设置为虚拟列表的大小。
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.
处理启用搜索在虚拟模式。如果未处理此事件,则和方法将返回null。
Handling the SearchForVirtualItem
event enables searching in virtual mode. If this event is not handled, the FindItemWithText
and FindNearestItem
methods will return null.
您可以处理,以便维护 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.
如果设置为Tile,当 VirtualMode
设置为true时,该值将自动更改为LargeIcon。
If the View
property is set to Tile, the value will automatically be changed to LargeIcon when VirtualMode
is set to true.
在虚拟模式下,集合被禁用。尝试访问它会导致。 集合和集合。如果要检索所选或已选项,请使用和系列。
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.
这篇关于最好使用:DataGrid或ListView显示大量数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!