有没有一个技巧来加快DataGridView1.DataSource的运行? [英] Is there a trick to speed up the running of DataGridView1.DataSource?

查看:205
本文介绍了有没有一个技巧来加快DataGridView1.DataSource的运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我填充了DataTable。 。 。它有大约350行,60列。



当我打电话时。 。 。



DataGridView1.DataSource = csvData; //这是将数据表中的行复制到dgv的位置。 。 。对于350个客户来说,填充时间是20-25秒。



20-25秒是否合理执行上述时间?我已将DataGridView1虚拟设置为true。我觉得时间过长了。 。任何增加速度的技巧?



最后,如果执行时间合理,你将如何实现与调用数据绑定到网格同步运行的进度条?你在哪里可以获得提供给栏的价值?

I have populated a DataTable . . . it has approximately 350 rows with 60 columns.

When I call . . .

DataGridView1.DataSource = csvData; //This is where rows in datatable are copied to dgv . . . for 350 clients time to populate is 20-25 sec.

Is 20-25 sec a reasonable time for execution of above? I have set DataGridView1 virtual set to true. I am thinking the time is excessive . . any tricks to increase speed?

Finally, if the execution time is reasonable, how would you implement a progress bar run in sync with the call to bind data to the grid? Where would you get the value to provide to the bar?

推荐答案

如果您正在执行的代码行正在设置DataSource并且该行需要20秒以上跑,没有什么可以做的,以加快这一阵容。您只需要一次性绑定所有信息。



您可以尝试将DGV VirtualMode属性设置为true。您将需要提供更多代码来处理现在将从网格触发的事件。您可以在此处找到相关教程[ ^ ]。



基本上,您提供的代码是DataSource,而不是仅提供数据。这允许您仅为网格将显示的行提供数据,从而加快操作速度。
If the line of code you're executing is setting the DataSource and that line takes 20+ seconds to run, no there is nothing you can do to speed that line up. You just have too much information you're binding to all at once.

You can try setting the DGV VirtualMode property to true. You'll have to provide a bit more code to handle the events that are now going to fire from the grid. You can find a tutorials on it here[^].

Basically, you're providing code to be the DataSource instead of providing just the data. This allows you to provide data for only the rows that the grid will display, speeding things up quit a bit.


这篇关于有没有一个技巧来加快DataGridView1.DataSource的运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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