以下是一段代码   
         foreach (StructD structData in List)
            {
                DateTime tt1 = DateTime.Now;                if (structData  == null)
                    continue;
                dataGrid_Modules.Rows.Add();
                int index = dataGrid_Modules.Rows.Count - 2;
                dataGrid_Modules.Rows[index].Cells[0].Value = mModulesList.IndexOf(structData);
                dataGrid_Modules.Rows[index].Cells[1].Value = structData .Id.ToString("x");
                dataGrid_Modules.Rows[index].Cells[2].Value = structData .Type;
                dataGrid_Modules.Rows[index].Cells[3].Value = structData .Rect.X;
                dataGrid_Modules.Rows[index].Cells[4].Value = structData .Rect.Y;
                dataGrid_Modules.Rows[index].Cells[5].Value = structData .Rect.Width;
                dataGrid_Modules.Rows[index].Cells[6].Value = structData .Rect.Height;
                dataGrid_Modules.Rows[index].Cells[7].Value = structData .Descript;                DateTime tt2 = DateTime.Now;
                TimeSpan tts = tt2 - tt1;
                Console.WriteLine("==============Update one Module time:" + tts.TotalMilliseconds);            }最后得出:
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:31.2498
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:0
==============Update one Module time:15.6249
==============Update one Module time:31.2498
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:31.2498
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:31.2498
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249
==============Update one Module time:15.6249200多个数据,加在一起就是
thread module:80ee2
================================Update Module total time:6187.4208
共6秒多,这种效率实在是无法忍受。
不知有什么办法可以解决?

解决方案 »

  1.   

    放到表里去,然后绑定到datagridview里试试
      

  2.   

    试了一下,好像可以。但是还有一个问题。
    因为绑定后,发现不能手动添加行。如果绑定后,那里面所有的行数据都由list列表中的数据来更新。 
    如果我想在最后多出一行,用于添加新数据的一个标识 
    比如最list中有n个对象,datagridview中则有n+1行,最后一行双击,则会新增加一个对象进list 
    同时datagridview中也会相应增加一行。 
    但datagridview中总是会多出一行,用于双击添加新对象。
      

  3.   

    可以手动添加行的,和数据源同步就可以了。至于多出一行,设一下AllowNew属性就可以了
      

  4.   

    dataGrid_Modules.DataSource=List; 不行?
      

  5.   

    你说的AllowNew是AllowUserToAddRows属性吧。
    我本身就是设置了的
    并且当我点击datagridview后,直接报异常并且是在main方法里
    SWF.Application.Run(form);索引为-1,越界了。而我在datagridview的selectedchanged事件中加发异常处理却没有捕获并且获得行索引正确
    是怎么回事呀?
      

  6.   

    Windows 窗体 DataGridView 控件中的性能优化
    靠人不如靠己 ,看MSDN吧!
      

  7.   

    要提高DatagridView的性能,只有找微软了.