gpt4 book ai didi

c# - 什么更好用: a DataGrid or ListView for displaying large amounts of data?

转载 作者:IT王子 更新时间:2023-10-29 04:23:56 28 4
gpt4 key购买 nike

我想在表格中显示 >50000 行。哪个控件最好用:DataGrid 还是 ListView(在详细 View 中)?这些控件中的哪一个将具有更好的性能?

最佳答案

正如 Hans 在对原始问题的评论中所说,它们的性能都将很糟糕,仅次于您的用户肯定会在同时显示如此多的数据行时感到不快.

但如果这在您的应用程序中是不可避免的(并且您提供了非常的搜索功能),那么您应该强烈考虑使用虚拟模式选项,无论哪种控制你决定使用。这意味着您必须提供自己的数据管理操作,而不是依赖控件为您完成。优点是事情要快得多。作为documentation说:

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 control :

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.

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.

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.

Handling the SearchForVirtualItem event enables searching in virtual mode. If this event is not handled, the FindItemWithText and FindNearestItem methods will return null.

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.

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.

关于c# - 什么更好用: a DataGrid or ListView for displaying large amounts of data?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6089674/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com