Adding Items to ListView too slow, please help

G

Guest

Hi

When i have my 144 items to display in my listview it is very fast (not seeing it
but when i have my 2204 items (it's "just" about 20 times more) it take
about half a minute to display the items
the code looks like this

for (int row=0;row<sucheErgebnisse.rowData.Count;row++

rowData = (String[])sucheErgebnisse.rowData[row]

item = new ListViewItem(rowData[0])
for (int sub=0;sub<rowData.Length-1;sub++

item.SubItems.Add(rowData[1+sub])

this.listView1.Items.Add(item)


as you see from a class sucheErgebnisse i take the String arra
and write it's content in an item, which will be added to the listView

any suggestions why this is so slow, or how to do it faster
(in explorer file displaying is also faster

thanks for help

nic
}
 
M

Marc Butenko

Try using SuspendLayout before starting the addition and ResumeLayout after
you are done adding your items.
 
H

Herfried K. Wagner [MVP]

* "Marc Butenko said:
Try using SuspendLayout before starting the addition and ResumeLayout after
you are done adding your items.

When adding items, no layouting is done.
 
M

Marc Butenko

My bad....I was thinking about the BeginUpdate and EndUpdate methods.

Whoops!

--
Marc Butenko
(e-mail address removed)
 
A

AlexS

Hi, Nick

You might have 2 reasons:
- redraw is slowing down adding - and redraw is caused by every add
operation
- sorting (internal)
- add loop itself

For first reason - use BeginUpdate before starting updating contents of
listview and EndUpdate when you finish.
For sorting - you might need to check how you sort items in listviews. On my
machine for example, custom sorting slows down filling process to approx 100
items per second.
You might need to check also add loop - do you some heavy processing inside
for added items?

HTH
Alex
 
G

Guest

Well, hi Alex

i must say i have forgotten to mention one important thing
the items as it looks are added very fast, like a few seconds
because the scrollbar at the side of the listview is going small (the move rectangle
continously, and stays at it's size for this long time and nothing happens
it's like there is some loop it calls which does unnecessasry thing
and then suddenly (nothing happens with the scrollbar) the items appear..
 

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