DataGridView Performance issue

F

FX

Hi all,
I'm using a CLR 2 component DataGridView and I'm encountered Performance
issue.
Here is the snippet :
string valueStr = value.ToString();
DataGridViewRowCollection rows = dataGridView1.Rows;
foreach (DataGridViewRow dataGridViewRow in rows) {
dataGridViewRow.Cells[0].Value = valueStr;
}

The type of first column is DataGridViewCheckBoxCell.
I takes more than 15 sec to execute this part of code (my component only
have 200 rows).

Does anyone has an idea to improve this ?

Thanks in advance
Fx
 
M

Marc Gravell

First - have you tested the performance outside of the debugger? (pref. in
release mode) Things can often be deceptive.

Second - it's not clear what your data is; if this is a custom class you
could look into the performance of the property setter? Or even (if a
bespoke class that provides property notifications) update the objects'
properties directly (perhaps suspending either UI updates or binding while
you do it).

Third - I'm not sure if it will help (I might misunderstand these
functions), but you could try preventing UI updates?

datagridview1.SuspendLayout(); // disable layout
try {
// your code
}
finally {
datagridview1.ResumeLayout(true); // enable and process pending
}

Fourth - weep

Marc
 

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