DataGridView + DataTable Speed

A

azraiyl

Hello,


When I create a DataTable and add 10000 rows my computer needs about
20ms. To delete 10000 rows it needs about 15ms.

When I connect the DataTable to a DataGridView it needs 3100ms to add
10000 rows and 6300ms to delete 10000 rows. That might be ok because
the control needs an update.

But when a disconnect the DataTable widht dgv.DataSoure = null it
needs 420ms to add 10000 rows and 2430ms to delete rows.

Can anyone explain what happened here and how I can modify the
DataTable so I get the performance when it is never bound to a
DataGridView?

Thanks in advance for any response

Azraiyl
 
M

Marc Gravell

Well, how did you bind it to the dgv? Was there a BindingSource
involved? Either way, controls (such as dgv) generally also speak to a
CurrencyManager via their BindingContext, so it is quite possible that
until you kill the form, that the ctx is still talking to the form
[but without any UI to redraw any more, hence not as slow]; the
BindingContext keeps a reference to the source as currency is shared
between alike sources.

Marc
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You need to provide more details, like if this is a win or a web based app.
In any case 10K of rows are a little too much, you should reduce the number
of rows. That will improve the performance al ot.
 
A

azraiyl

@Marc Gravell

I did bind it with "dgv.DataSource = dt". Thanks for your information
about this CurrencyManager, have first to google about it.

@Ignacio Machin

It doesn't matter if i add 1000 or 10000 rows, after binding the
insert/delete operations are slow, before binding insert/delete
operations are fast. It is a windows application.
 
A

azraiyl

My initial problem was, show 100000+ records, add them fast and delete
them
fast. First I tried to do it with ListView. ListView was awfull slow,
therefore
I had the idea with DataGridView. But it looks like DataGridView has
its own
strage behaviour. After all I was reading something about VirtualMode
in
ListView.

My solution:

Setup a List<ListViewItem> and add, delete only on this List. Working
with this
list is fast (it has a RemoveRange method too). Adding and deleting
100000
records/s is no problem.

The only thing you have to remeber is that ListView has more then one
bug:

http://blogs.msdn.com/cumgranosalis/archive/2006/03/18/ListViewVirtualModeBugs.aspx
 

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