Dynamic ListView in .NET?

I've got a question for all you .NET gurus out there: is there any way to, instead of populating a ListView with say 10,000 items, simply tell it that there is a total of 10,000 items (so the scrollbar can be initialized properly), and then catch some kind of event (like ListView.OnShowItem(int itemNum)) that I can use to dynamically set the text of this item at the last minute for those items that are actually visible?

An approach like that could drastically speed up the redrawing of SharpReader's headline-pane, but I can't for the life of me figure out how to do this in .NET.

TrackBack URL for this entry: http://www.hutteman.com/scgi-bin/mt/mt-tb.cgi/90
Comments

Not tested, but I would recommend to override the WndProc method and handle the WM_VSCROLL message, and use it to when scrolling down one row, delete the top item, and insert a new item at the bottom.

Posted by Stephane Rodriguez at November 13, 2003 2:20 AM

The underlying list control supports virtual items so I see no reason why the .NET one shouldn't. Can't tell you how though!

Posted by Simon at November 13, 2003 3:05 AM

I experimented a few weeks ago with the virtual listview (I have example code here). The speed is very impressive!
But because of many other problems arising with using that feature (issues/influenced code: column-reorder, sorting, drag an item, threaded view) I moved that to a time in the future to deal with (and maybe make a separate control with all that support build in). If you have time and want to have some fun, I can send you my experimental code.

Posted by TorstenR at November 13, 2003 3:45 AM

Why not simply use DataGrid - it has requested "virtual" functionality + options to sort ...

Posted by The Dude at November 13, 2003 5:44 AM

I'm curious why you chose the ListView instead of the DataGrid (this isn't a criticism at all, I'm always fascinated about why people choose one way over another)? In VB6 I was a huge fan of ListViews but it seems like people have moved towards DataGrid in .NET.

Posted by Marc Shiker at November 13, 2003 8:21 AM

Luke,
You can find a Virtual Listview for download here. Its completely free, with source code. I haven't used it, so I can't vouch for its quality, but it may be worth looking into.

Posted by Jacob at November 13, 2003 9:21 AM

hrm, that link didn't take correctly, it appears. The URL is: http://www.windowsforms.com/ControlGallery/ControlDetail.aspx?Control=214&tabindex=9

Posted by Jacob at November 13, 2003 9:22 AM

You definately want to use a virtual listview for this. In Win32, you'd be using the LVN_GETDISPINFO notification to populate when you get an item notification. See this google thread on how to easily implement this in .NET:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&threadm=0dhn9.6492%24s5.193245%40twister.southeast.rr.com&rnum=4&prev=/groups%3Fq%3Dvirtual%2Blistview%2B.net%26hl%3Den%26lr%3D%26ie%3DUTF-8%26safe%3Doff%26selm%3D0dhn9.6492%2524s5.193245%2540twister.southeast.rr.com%26rnum%3D4

Posted by Steve at November 13, 2003 10:01 AM

Here's the MSDN article on creating a virtual listview:

Virtual ListView Control

Cheers!

Posted by Hans at November 13, 2003 1:53 PM

Perhaps I don't fully grasp your needs but it seems to me that an owner drawn listbox does exactly what you're asking. I belive you have to store the full number of objects in it for it to know how to draw the scrollbars but you don't have to store the real object, just a representative object. The Listbox then raises the DrawItem event with the index of the item to draw and the location of where to draw it.

Perhaps your issue is more with having to stuff 10000 items into the listbox in which case this isn't what you want. I just tested the ones I'm using and I've found that they only raise DrawItem for the items that are actually visible. Since you're doing the drawing you are under no obligation to use anything in the listbox other than the index.

Is that not what you're after?

Posted by Steve Hiner at November 13, 2003 2:49 PM

Virtual ListView (or

Trackback from AddressOf.com at November 13, 2003 4:26 PM

Where is the headline pane?... I keep seeing other panes in SharpReader screenshots but I do not see them on my desktop.

I think I may have resized them and resized them where I can not get them back?

Posted by Michael Guilfoyle at November 13, 2003 6:10 PM

I got one working using this code as a base:
http://www.freeweb.hu/noiseehc/VirtualListView.cs

Posted by Geoff Stockham at November 17, 2003 5:34 AM

use the lockwindow api to disable screenupdates , will speedup the listview when you populate it...

//Roger

Posted by roger at November 19, 2003 5:26 AM

It was recommended several times - take Virtual Listview. It is working exactly like you requested. I'm meanwhile replacing all grid/tree like components in my project (which is also a rss-aggregator) with virtual listview's and I made best experiences with this. Take it, Luke, you will not regret it.

Kind regards
Christian

Posted by Christian at November 20, 2003 4:22 AM
This discussion has been closed. If you wish to contact me about this post, you can do so by email.