Why is datagrid update SO slow?

  • Thread starter Thread starter VM
  • Start date Start date
V

VM

I have a 35000 line datagrid and updating one field in all 35000 rows takes
an eternity. How come? Since I don't have the datasource available (it may
be a table or view), in my example I do it like this:

for (int i=0;i<34000;i++) //the first 2000 records took 2 mins.
{
dataGrid_auditAddress[i, 5] = "MARKED";
}

Any help would be appreciated.
 
Hi,

Well, it depends on the grid. However, why would you need 35000 records?
What grid are you talking about? Did you try BeginUpdate/EndUpdate?
It is a bad idea having that many records in a grid.
 
VM,

Well, the fact that you are performing 35000 updates is part of it. I
would recommend actually going to the data source, updating all 35000 rows,
then calling AcceptChanges on the table/view that they are in. This should
make it faster.

It would be nice if the grid supported the ability to not update itself
during an operation, but in order to do this, you will have to detach the
data source, update the table, and then reattach.

Hope this helps.
 
But in the process of updating the windows datagrid I also update an ascii
file by writing each row (in our case, 35000) to the file. And the whole
process of opening the file, writing to it 35,000.times, and closing takes
less than a second (almost instantaneous). So imagined it'd be almost the
same speed.
 
It's a Windows datagrid. Basically, I use the grid to load the file to it,
modify certain aspects of the file through the grid, and write the grid to
the file. These files are usually HUGE and our goal is to be able to do this
with 1.6 million records (which means 1.6m rows). So 35,000 isn't that many
considering what we have to accomplish. And although a normal user will only
highlight a few records and update the file with those few records, we're
prepping up to the possibility that a user will want to highlight and modify
all 35,000 records.

The datagrid is mostly a visual commodity so the user knows what he has
updated (ie. when a user highlights one record and right-clicks, the grid
will update column X with the words "right-clicked"). Now, If we highlight
all 35,000 records, it'll have to go to all 35,000 rows and write
"right-clicked". That's what takes so long.

It was either the grid or a listview.

Angel

Miha Markic said:
Hi,

Well, it depends on the grid. However, why would you need 35000 records?
What grid are you talking about? Did you try BeginUpdate/EndUpdate?
It is a bad idea having that many records in a grid.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

VM said:
I have a 35000 line datagrid and updating one field in all 35000 rows takes
an eternity. How come? Since I don't have the datasource available (it may
be a table or view), in my example I do it like this:

for (int i=0;i<34000;i++) //the first 2000 records took 2 mins.
{
dataGrid_auditAddress[i, 5] = "MARKED";
}

Any help would be appreciated.
 
How can I get the datasource from a datagrid?
I was thinking of getting the datasource, be it a dataview or datatable,
cast it, and then do all the necessary changes. Since I don't know what the
source may be, I don't want to write some code for a datatable and even more
code if it's a dataview.


Nicholas Paldino said:
VM,

Well, the fact that you are performing 35000 updates is part of it. I
would recommend actually going to the data source, updating all 35000 rows,
then calling AcceptChanges on the table/view that they are in. This should
make it faster.

It would be nice if the grid supported the ability to not update itself
during an operation, but in order to do this, you will have to detach the
data source, update the table, and then reattach.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


VM said:
I have a 35000 line datagrid and updating one field in all 35000 rows takes
an eternity. How come? Since I don't have the datasource available (it may
be a table or view), in my example I do it like this:

for (int i=0;i<34000;i++) //the first 2000 records took 2 mins.
{
dataGrid_auditAddress[i, 5] = "MARKED";
}

Any help would be appreciated.
 
Why dont you only update the file and just refresh the grid, instead of
modifying grid rows. Refreshing grid should reflect the modified data.

VM said:
But in the process of updating the windows datagrid I also update an ascii
file by writing each row (in our case, 35000) to the file. And the whole
process of opening the file, writing to it 35,000.times, and closing takes
less than a second (almost instantaneous). So imagined it'd be almost the
same speed.


VM said:
I have a 35000 line datagrid and updating one field in all 35000 rows takes
an eternity. How come? Since I don't have the datasource available (it may
be a table or view), in my example I do it like this:

for (int i=0;i<34000;i++) //the first 2000 records took 2 mins.
{
dataGrid_auditAddress[i, 5] = "MARKED";
}

Any help would be appreciated.
 
Back
Top