locked
Performance whe comparing and using datagridview RRS feed

  • Question

  • Hi!

    Im making an appl that reads data from two files, delimited with a sign.
    Then the appl compare the data and if there is a diffrence, the data from both the files are combined and displayed as a row in a datagridview. Now for differences below 100 theres no problem but when it reaches above 1000 the appl becomes unresponsive...
    So what is generally the best way to add a lots of rows to the datagridview?
    The data that should be added is contained in a List<string[]> where each string in the string[]array should be a cell in the row

    Thursday, June 23, 2011 4:19 AM

Answers

  • if (!Comp.ABORT)
       {
        DG_Result.Invoke((MethodInvoker)delegate
        {
         foreach (string[] o in Comp.Result)
         {
           DG_Result.Rows.Add(o);
          //int i = DG_Result.Rows.Add(new DataGridViewRow());
          // for (int s = 0; s < o.Length; s++)
          //  DG_Result[s, i].Value = o[s];
         }
        }
       );
       }
    
    
    Woa, this did the trick....
    Thursday, June 23, 2011 5:21 AM

All replies

  • Hi,

    would you mind showing us the code you got there?


    Mitja
    Thursday, June 23, 2011 4:44 AM
  •  private void FillGridWorker_DoWork(object sender, DoWorkEventArgs e)
    
        {
          if (!Comp.ABORT)
          {
            DG_Result.Invoke((MethodInvoker)delegate
            {
              foreach (string[] o in Comp.Result)
              {
                int i = DG_Result.Rows.Add(new DataGridViewRow());
                for (int s = 0; s < o.Length; s++)
                  DG_Result[s, i].Value = o[s];
              }
            }
          );
          }
        }
    
    Even though i run this in a bg_Worker it still takes ages to add >1000 rows.....

    Thursday, June 23, 2011 4:54 AM
  • if (!Comp.ABORT)
       {
        DG_Result.Invoke((MethodInvoker)delegate
        {
         foreach (string[] o in Comp.Result)
         {
           DG_Result.Rows.Add(o);
          //int i = DG_Result.Rows.Add(new DataGridViewRow());
          // for (int s = 0; s < o.Length; s++)
          //  DG_Result[s, i].Value = o[s];
         }
        }
       );
       }
    
    
    Woa, this did the trick....
    Thursday, June 23, 2011 5:21 AM