为什么DataGridView这么慢? [英] Why is DataGridView so slow?

查看:154
本文介绍了为什么DataGridView这么慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个数据绑定DataGrid,然后研究了DataGridView,发现它更符合我的需求。我有一个DataGridViewCheckBoxColumn作为我的DataGridView中的第一列,然后将其数据源设置为DataSet。有时,DataSet可能包含超过1000行的表。用户有一个按钮,可以选择DataGridView中的所有复选框。我的foreach循环用DataGridView完成此任务大约需要5分钟。使用DataGrid,它是毫秒。到底是怎么回事?有什么建议?以下是一些代码。

I created a databound DataGrid, and then researched DataGridView to find it would fit my needs better.  I have a DataGridViewCheckBoxColumn as my first column in my DataGridView then set its datasource to a DataSet.  Sometimes the DataSet may contain a table with over 1000 rows.  The user has a button that will select all checkboxes in the DataGridView.  It takes about 5 minutes for my foreach loop to complete this task with the DataGridView.  With the DataGrid, it was milli-seconds.  What is going on?  Any suggestions?  Here is some of the code.

提前致谢,

ryan

//我的DataGridViewCheckBoxColumn truevalue = 1

//my DataGridViewCheckBoxColumn truevalue = 1

foreach DataGridViewRow dgr in dtgPolicies.Rows)

foreach(DataGridViewRow dgr in dtgPolicies.Rows)

{

{

DataGridViewCell dgc =( DataGridViewCell )dgr.Cells [ " O" ];

                DataGridViewCell dgc = (DataGridViewCell)dgr.Cells["O"];

dgc.Value = 1 ;

                dgc.Value = 1;

}

推荐答案

不太相似重新考虑DataGridView的这种行为,但是如果正在使用的DataGridView绑定到某些DataSource,那么更新DataSource所有行中列的值就不会给你带来这种性能延迟。

希望这有帮助!!

-Jay


这篇关于为什么DataGridView这么慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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