ListView loading slowly

D

David

I am loading a ListView like this...

foreach (DataRow dr in dt.Rows)
{
ListViewItem lvi= new ListViewItem((string)dr["field1"]);
lvi.Tag = (string)dr["field2"];
listviewTest.Items.Add(lvi);
}

The DataTable is large and the ListView takes a long time to load. What can
I do to speed this up?

TIA

David
 
M

Marc Gravell

Also - try (in the loop) adding the new ListViewItem objects to a
List<ListViewItem> - then at the end call
..Items.AddRange(yourList.ToArray()); - this reduces the number of calls into
the list view; supprounding this last call with BeginUpdate / EndUpdate may
also help, but if you are only making one call I would expect it to handle
that internally without painting each time... but best to be paranoid and
use them anyway ;-p

Marc
 
J

James

hi David,
please load your listview in load function of your control/Form. Use
BeginUpdate /EndUpdate. Use of Double buffering in your list view
might increase performance a little bit. if your listview contains
large number of itmes then use Virtual Listview Mode. the main problem
comes of flickering is also when the columns are resized. So better,
hook its paint events in Wndproc.
Hope this helps. :)

James
 
D

David

Hi James,

What is Virtual ListView Mode? I have read about a virtual ListView
control. I have considered it - looks like I would have to write it in C++
and would require more time.

Thanks.

David

James said:
hi David,
please load your listview in load function of your control/Form. Use
BeginUpdate /EndUpdate. Use of Double buffering in your list view
might increase performance a little bit. if your listview contains
large number of itmes then use Virtual Listview Mode. the main problem
comes of flickering is also when the columns are resized. So better,
hook its paint events in Wndproc.
Hope this helps. :)

James

I am loading a ListView like this...

foreach (DataRow dr in dt.Rows)
{
ListViewItem lvi= new ListViewItem((string)dr["field1"]);
lvi.Tag = (string)dr["field2"];
listviewTest.Items.Add(lvi);
}

The DataTable is large and the ListView takes a long time to load. What
can
I do to speed this up?

TIA

David
 
D

David

Thanks Everyone, for the suggestions...

I am not necessarily wedded to the ListView. I need to do tests next week
when I get some time. A ListBox would do, which I suspect would be lighter
weight, and I could use data binding. Also, I am wondering if a DataGrid
would be more optimized than the ListView.

Any thoughts on the above?

David
 

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