Tags: arraylist, bind, contains, datagridview, forms, net, number, records, rows, speed, web

How to speed up datagridview

On .Net » Web Forms

3,338 words with 9 Comments; publish: Sun, 30 Dec 2007 00:09:00 GMT; (10093.75, « »)

Hi, I have a datagridview and i bind it to an arraylist. The arraylist contains about 50 000 of records. When a large number of rows(say 49000) being selected and I try to remove them all at once, it's such a lengthy process almost takes me 20mins. I have been looking for the solution all over the net, but i still couldn't find any.

I have read an article on "Using the Selected Cells, Rows, and Columns Collections Efficiently" but it didn't tell me how to determine which rows are selected. So I can't determine which rows need to be removed from the datagridview.

Can anyone help me with the problem?

All Comments

Leave a comment...

    • use a separate thread. Something like this:


      public Delegate void dRemoveRows;

      public void WhateverIsCalledToRemove()


      yourdgv.Invoke(new dRemoveRows(RemoveRowsAsync));


      public void RemoveRowsAsync()


      // Remove the Rows here



      #1; Wed, 05 Sep 2007 10:54:00 GMT
    • thx for the suggestion. However, the problem now is that it's takking too long. all my other function depends on its finaly result. So i can't do anything before it's been done

      #2; Wed, 05 Sep 2007 10:55:00 GMT
    • How are you removing the rows?

      Many times it is faster to manipulate the datasource than the actual datagridviews rows. You might see improvements by modifying the ArrayList instead of the DataGridView.

      #3; Wed, 05 Sep 2007 10:56:00 GMT
    • You are right , i have notice that problem. I am deleting the item for the arraylist, but even without the deleting it's still taking about the same time. The code i had is following:

      for (int i = 0; i < dgvResult.SelectedRows.Count; i++)


      DataGridViewRow row = dgvResult.SelectedRows;

      // al.RemoveAt(row.Index);

      // row.Selected = false;


      That loop takes ages if rows.count is large!!

      #4; Wed, 05 Sep 2007 10:57:00 GMT
    • Also make sure to disable all the XXXAuto(Re)Size properties...
      #5; Wed, 05 Sep 2007 10:58:00 GMT
    • That doesn't help
      #6; Wed, 05 Sep 2007 10:59:00 GMT
    • I think if you try virtual mode will make it performace better.
      #7; Wed, 05 Sep 2007 11:00:00 GMT
    • That doesn't help

      How are you removing the records? If you have, please post some code sample.

      #8; Wed, 05 Sep 2007 11:01:00 GMT
    • Here is the code i used to remove the records in my datagridview:

      //get the tot number of rows been selected, usually > 30000 records

      int tot = dgvResult.SelectedRows.Count;

      for (int i = 0; i < tot; i++)


      //gets the index of the selected row

      DataGridViewRow row = dgvResult.SelectedRows;

      //remove it from the al, where al is an arraylist bind to the gridview



      Basically, i just want to know which rows have been selected, then remove it from its datasource which is an arraylist. But somehow , it's really slow. Removing 100 record is ok, but if you try to remove more than 1000 you will start to feel the delay. When I try to remove 20000 record, the program just stucks in there. Anyone got any ideas?

      #9; Wed, 05 Sep 2007 11:02:00 GMT