给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; 
            }

解决方案 »

  1.   

    个人认为使用数据绑定来得快,而且数据绑定你不一定要添加DataSet的,你可以添加一个List<T>类型,其中T为自定义类。
    如果你使用了VS2008,那么用Linq产生List<T>的值真的是易如反掌,效率极高。
      

  2.   

    绑定数据源肯定会快点。
       可以考虑用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;
      

  3.   

    通过分页存储过程提高gridview的效率还可使用List<T>绑定到gridview
      

  4.   

    datagirdview不是这么用的
    dg.DataSource = 数据源
    dg.DataBind();你的数据存在数据源中,可以利用分页显示数据提高速度