简体   繁体   English

如何最好地将大量数据添加到DataGridView

[英]How to best add HUGE amount of data to DataGridView

I am reading a long text file with currently round about 900.000 lines (log files). 我正在阅读一个长文本文件,当前大约有900.000行(日志文件)。 I am then filling a DataTable object with the data and until then everything is fine. 然后,我用数据填充DataTable对象,然后一切都很好。 But when assigning the huge DataTable object to the DataGridView.DataSource it takes ~ 10 minutes until the application is responsive again and the DataGridView shows the data. 但是,当将巨大的DataTable对象分配给DataGridView.DataSource时,大约需要10分钟,直到应用程序再次响应并且DataGridView显示数据。 The same happens if I load the data to the DataGridView directly without a DataTable object. 如果我不使用DataTable对象直接将数据加载到DataGridView,也会发生相同的情况。 Is there a better way to work with this huge amount of data and a DataGridView? 有没有更好的方法来处理大量数据和DataGridView?

Yes; 是; you need to enable "virtual mode". 您需要启用“虚拟模式”。 This isn't entirely trivial, as you need to provide the code to provide cell values on-demand (rather than filling everything in advance), but it isn't horrendous either. 这并非完全无关紧要,因为您需要提供代码以按需提供单元格值(而不是预先填充所有内容),但这也不可怕。 Here's a complete walkthrough in the Microsoft docs. 这是 Microsoft文档中的完整演练

However, from a UX perspective, maybe a better solution is to make it such that you don't need to display nearly a million lines in a grid . 但是,从用户体验的角度来看,也许更好的解决方案是使它不需要在网格中显示将近一百万行 That isn't a useful user experience, in most cases. 在大多数情况下,这不是有用的用户体验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM