C# Assigning a value to DataRow["haswhatnots"] = hasWhatnots is awful slow. hasWhatnots is a boolean value.
I have profiled this line and with 560000 hits the execution time is 82 seconds. Of course the profiler has some effect on the performance, but still the performance of this is grazy slow!
Any hints on the issue. The DataRow is part of a DataTable which is bound to BindingSource that is bound to DataGridView.Datasource.
(edit: only just saw that you are data-binding)
The first thing to try is disabling data-binding; perhaps set the source to null and re-bind afterwards. BindingSource
has SuspendBinding()
, ResumeBinding()
and ResetBindings()
for this.
If the real problem is just lookup, you could take a snap of the DataColumn
, and use:
// early code, once only...
DataColumn col = table.Columns["haswhatnots"];
// "real" code, perhaps in a loop
row[col] = hasWhatnots;
I seem to recall that this is the fastest route (the string overload locates the DataColumn
from the list).
Alternatively - use a class
model instead of DataTable
;-p
You could try this
bindingSource1.RaiseListChangedEvents = false;
// stuff the grid
bindingSource1.RaiseListChangedEvents = true;
and see if it makes a difference.
Very late, but still had the same issue
DataRow row
row.BeginEdit();
row["haswhatnots"] = hasWhatnots;
row.EndEdit();
There were extreme lags, occuring on (in my scale) large grids (60 cols, 10k+ rows), and this cutted the cpu time to less then one percent to what it was before.