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
Tim Wilson - 23 Jun 2006 02:18 GMT
Try using the BeginUpdate/EndUpdate methods.

Signature
Tim Wilson
Device Application Development MVP
>I am loading a ListView like this...
>
[quoted text clipped - 11 lines]
>
> David
Marc Gravell - 23 Jun 2006 08:47 GMT
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
James - 23 Jun 2006 12:50 GMT
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...
>
[quoted text clipped - 11 lines]
>
> David
David - 24 Jun 2006 14:15 GMT
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
> hi David,
> please load your listview in load function of your control/Form. Use
[quoted text clipped - 23 lines]
>>
>> David
David - 24 Jun 2006 14:22 GMT
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
>I am loading a ListView like this...
>
[quoted text clipped - 11 lines]
>
> David