How to suspend DataGridView while I am updating a lot of data?

H

hjin

DataGridView takes very much time if I update a lot of data

I have a DataGridView which has a DataSource (a DataTable) of 3000
rows. If I want to update one column of every rows in the DataTable,
my whole appliation freezes with any response. After a lot of time, it
comes back.

If I set the DataSource to null before changing the data and set it
back after changing. There' s no problem. But I lost the status of the
DataGridView, like current selected row, sorting, etc.

Is there any way to prevent the DataGridView to do anything while I am
updating the data in the DataTable?
 
B

Boaz Ben-Porat

Have you tried dataGridView1.SuspendLayout () ?

I haven't tried it myself, but i think it works.

Boaz Ben-Porat
Milestone systems A/S
Denmark
 
H

hjin

I tried SuspendLayout and SuspendBinding. All didn't work.

Finally I found because I set all columns' AutoSize to AllCells,
everytime I changes a value in one cell, it goes through all the cells
in the column to recaculate the column's width. I think it's a bad
code because it already knows the preivous width and it should only
caculate the width of the changed cell. I have to set the columns'
AutoSize to None before changing the data and set them back to
AllCells afterwards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top