给datagirdview 添加上百,千条数据,怎么让它速度快,效率高?不知道大家是不是用这样循环的方法来添加啊?是不是我方法不好。 如果用数据绑定也要给DataSource添加行列啊,试过也差不多慢啊!
for (int i =0 ; i < last; i++)
{
dgPoint.Rows.Add();
dgPoint.Rows[i].Cells[0].Value = sensors[i + page * txtnumber].SName;
dgPoint.Rows[i].Cells[0].Tag = sensors[i + page * txtnumber].SID.ToString();
SensorBLL.SensorType(sensors[i + page * txtnumber]);
dgPoint.Rows[i].Cells[1].Value = sensors[i + page * txtnumber].SensorType.STName;
Subject sub = SubjectBLL.Select(Convert.ToInt32(sensors[i + page * txtnumber].SP29));
dgPoint.Rows[i].Cells[2].Value = sub.subjectType;
dgPoint.Rows[i].Cells[3].Value = sub.subjectName;
dgPoint.Rows[i].Cells[6].Value = sensors[i + page * txtnumber].SP30;
Section sec = SectionBLL.Select(Convert.ToInt32(sensors[i + page * txtnumber].SP28));
dgPoint.Rows[i].Cells[4].Value = sec.SectionPart;
dgPoint.Rows[i].Cells[5].Value = sec.SectionName;
dgPoint.Rows[i].Cells[7].Value = sensors[i + page * txtnumber].SP27;
dgPoint.Rows[i].Cells[8].Value = sensors[i + page * txtnumber].SP26;
}
for (int i =0 ; i < last; i++)
{
dgPoint.Rows.Add();
dgPoint.Rows[i].Cells[0].Value = sensors[i + page * txtnumber].SName;
dgPoint.Rows[i].Cells[0].Tag = sensors[i + page * txtnumber].SID.ToString();
SensorBLL.SensorType(sensors[i + page * txtnumber]);
dgPoint.Rows[i].Cells[1].Value = sensors[i + page * txtnumber].SensorType.STName;
Subject sub = SubjectBLL.Select(Convert.ToInt32(sensors[i + page * txtnumber].SP29));
dgPoint.Rows[i].Cells[2].Value = sub.subjectType;
dgPoint.Rows[i].Cells[3].Value = sub.subjectName;
dgPoint.Rows[i].Cells[6].Value = sensors[i + page * txtnumber].SP30;
Section sec = SectionBLL.Select(Convert.ToInt32(sensors[i + page * txtnumber].SP28));
dgPoint.Rows[i].Cells[4].Value = sec.SectionPart;
dgPoint.Rows[i].Cells[5].Value = sec.SectionName;
dgPoint.Rows[i].Cells[7].Value = sensors[i + page * txtnumber].SP27;
dgPoint.Rows[i].Cells[8].Value = sensors[i + page * txtnumber].SP26;
}
解决方案 »
- 父窗体中加入一个Panel,然后将要弹出的窗体作为Panel的控件显示到Panel上
- 请问,常用的类名有哪些
- 事件是委托的实例呢?还是:事件也是一个类呢?
- 数据备份登陆失败
- C#里怎么控制timer控件?
- 我想做个程序能自动分析TCP头,如果有含有torrent文件类型的字符,就断了这个连接
- 请教关于访问ArrayList中元素的问题
- 我用C#编的程序在其它系统(机器)下用不了,是不是兼容性问题?
- C#中访问ORACLE存储过程有问题?
- skyline terra explorer pro C# 动态路线转移 代码 没有错,运行后报错
- 急寻如下简单需求的解决方案,在线等!
- 请教两个问题....
如果你使用了VS2008,那么用Linq产生List<T>的值真的是易如反掌,效率极高。
可以考虑用List<T>泛型集合
T为你的操作的自定义类。 public class test
{
private string userName;
public string UserName
{
get { return userName; }
set { userName = value; }
} private string uPwd;
public string UPwd
{
get { return uPwd; }
set { uPwd = value; }
}
}
List<test> list = new List<test>();
test te = new test();
te.UserName = "a";
te.UPwd = "b";
list.Add(te);
........
this.dataGridView.DataScoure=list;
dg.DataSource = 数据源
dg.DataBind();你的数据存在数据源中,可以利用分页显示数据提高速度