469,365 Members | 1,749 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,365 developers. It's quick & easy.

Listview (slow when adding items)

Hello,

Is there a solution to the following problem :
When filling a listview (30 columns) with around 5000 items, it can take
easily 10 sec for the listview to be filled.

I have used BeginUpdate and SuspendLayout but no speed...

Here is a flavor of the code :

MyListView.BeginUpdate();
MyListView.SuspendLayout();
.....
....
(loop_fill)
ListViewItem MyItem = new ListViewItem(...parms...);
MyItem.SubItems.Add(...parms...);
MyItem.SubItems.Add(...parms...);
MyItem.SubItems.Add(...parms...);
....
MyListView.Items.Add(MyItem);
(loop_fill_end)
MyListView.EndUpdate();
MyListView.ResumeLayout();
But it is still slow...
Is the slowness of the listview a known issue ?
Any idea ?
Regards,
Cybertof.
Nov 16 '05 #1
2 8625
> Is there a solution to the following problem :
When filling a listview (30 columns) with around 5000 items, it can take
easily 10 sec for the listview to be filled.

Adding items to a ListView is slow but using AddRange() instead of Add() can
help a bit.
Passing all subitems of a ListViewItem in form of an string[] might also
help speed things up.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk
Nov 16 '05 #2
cybertof <cy****************@gmx.net> wrote in message news:<MP************************@msnews.microsoft. com>...
Hello,

Is there a solution to the following problem :
When filling a listview (30 columns) with around 5000 items, it can take
easily 10 sec for the listview to be filled.

I have used BeginUpdate and SuspendLayout but no speed...

Here is a flavor of the code :

MyListView.BeginUpdate();
MyListView.SuspendLayout();
....
...
(loop_fill)
ListViewItem MyItem = new ListViewItem(...parms...);
MyItem.SubItems.Add(...parms...);
MyItem.SubItems.Add(...parms...);
MyItem.SubItems.Add(...parms...);
....
MyListView.Items.Add(MyItem);
(loop_fill_end)
MyListView.EndUpdate();
MyListView.ResumeLayout();
But it is still slow...
Is the slowness of the listview a known issue ?
Any idea ?
Regards,
Cybertof.


I had this same problem. A huge speed increase is to use AddRange()
instead of Add(). In your loop, collect all of your items into an
array. Then when the loop is finished, call
MyListView.Items.AddRange(MyItems) once.
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Anushya | last post: by
reply views Thread by Anushya | last post: by
reply views Thread by Ryan Dawson | last post: by
18 posts views Thread by mrshrinkray | last post: by
4 posts views Thread by firefox | last post: by
9 posts views Thread by Kadett | last post: by
3 posts views Thread by RT | last post: by
1 post views Thread by =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.