更新数据源运行时,DataGridView被冻结/组合。 [英] DataGridView is frozen/gang while updating the datasource runtime.

查看:85
本文介绍了更新数据源运行时,DataGridView被冻结/组合。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在我的应用程序中使用了DataGridView控件。最初,我已经加载了10000行和50列。我的方案是更新特定时间间隔的数据源(使用Timer)。

I have used DataGridView control in my application. Initially,i have loaded the 10000 rows and 50 columns in it. My scenario is that updating the data source for particular time interval(using Timer).


问题:在更新数据源时执行动作(cell_click,滚动等)时网格已被冻结/帮派。

Problem: The grid has been frozen/gang when performing the action(cell_click, scrolling,etc) while updating the datasource.


如何解决此问题?有没有解决方法?

How to resolve this issue? Is there any workaround?

timer = new Timer();
this.timer.Interval = 1000;
this.timer.Tick += new System.EventHandler(this.timer1_Tick);

private void timer1_Tick(object sender,EventArgs e)
{
// try
{
timer.Stop();
for(int i = 0; i< 10000; i ++)
{
var row = r.Next()%10000;
for(int col = 1; col< 10; col ++)
{
var colNum = r.Next()%55;
if(table!= null)
table.Rows [row] [colNum] =" hi"; // r.Next()。ToString();
}
}
table.AcceptChanges();
timer.Start();
}
}

private void timer1_Tick(object sender, EventArgs e) { //try { timer.Stop(); for (int i = 0; i < 10000; i++) { var row = r.Next() % 10000; for (int col = 1; col < 10; col++) { var colNum = r.Next() % 55; if (table != null) table.Rows[row][colNum] = "hi";// r.Next().ToString(); } } table.AcceptChanges(); timer.Start(); } }




谢谢。

推荐答案

除非您拥有超级计算机,否则无法提出要求。 

what you are asking is not possible unless you have a super computer. 

当用户最多可以看到几十行时,每秒更新10000行是没有意义的。你只是在浪费CPU时间。仅更新用户实际看到的行。 datagridview类具有虚拟模式。 

it does not make sense to update 10000 rows every second when the user can see a couple dozen rows at most. you are just wasting CPU time. Only update the rows that the user actual sees. The datagridview class has a virtual mode for this. 


这篇关于更新数据源运行时,DataGridView被冻结/组合。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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