List Info

Thread: Getting to know the ListView VirtualMode




Getting to know the ListView VirtualMode
user name
2006-07-11 19:48:25
Peter,

Thanks for an extremely thorough and detailed explanation.
I'm humbled.

Rick

-------------- Original message from Peter Ritchie
<discuss.develop.comPETERRITCHIE.COM>: --------------


> VirtualMode performs no caching of data--the
application is responsible
> for *all* caching of data (hence the CacheVirtualItems
event, which is a
> hint to the application that a group of ListViewItems
are going to be
> requested). Whenever any part of a ListViewItem needs
repainting, the
> RetrieveVirtualItem event is raised. My tests back that
up. Simply
> calling Invalidate() on a ListView causes all visible
items to be re-
> queried via RetrieveVirtualItem.
>
> VirtualMode simply sets the ListView windows style of
LVS_OWNERDATA which
> documents "Except for the item selection and
focus information, the owner
> of the control must manage all item information. ...
Because this type of
> list control is intended for large data sets, it is
recommended that you
> cache requested item data to improve retrieval
performance. The list view
> provides a cache-hinting mechanism to assist in
optimizing the cache. The
> hint is implemented in the form of an LVN_ODCACHEHINT
notification
> message." The LVN_ODCACHEHINT is wrapped by the
> ListView.CacheVirtualItems event.
>
> RedrawItems() would do the same thing as Invalidate(),
as long as you set
> the invalidate argument to true. Under the covers,
RedrawItems() sends a
> LVM_SETITEMPOSITION to the control and calls the Update
method; which only
> updates invalidated regions of the control by sending a
WM_PAINT message.
> Whereas Invalidate() first sets the update region and
forces a WM_PAINT
> message.
>
> The side-effect of RedrawItems() is that it will move
the visible items in
> icon or small icon view, depending on the values you
pass to the method.
> Probably not a side-effect you want. Of course, you can
calculate the
> indexes of the visible items to pass to RedrawItems();
but, it's wasted
> cycles.
>
> Also, using ListViewItem.Selected and .Focused worked
fine in my tests.
> There's nothing documented about them not working when
VirtualMode is
> true. I think there was some chatter with some of the
beta and CTP
> releases of Visual Studio 2005 where a ListViewItem
from a ListView whose
> VirtualMode property is set to true could be
disconnected from the
> ListView, resulting in ListViewItem.Selected or
.Focused not working (the
> work-around, of course, was to set the ListView
property of the
> ListViewItem object in the RetrieveVirtualItem event
handler). That is
> not the case in the release versions of the framework.
Whenever the
> framework calls OnRetrieveVirtualItem(), it always
updates the
> ListViewItem.ListView property immediately--ensuring
that both the
> Selected and Focused properties work in virtual mode.
>
> -- Peter
> Microsoft MVP, Visual Developer - Visual C#
> http://www.peterRit
chie.com/blog/
>
> On Tue, 11 Jul 2006 18:30:44 +0000, Richard Kucia
wrote:
>
> >I'm not sold that Invalidate() will work correctly
when the ListView is
> in VirtualMode. I suspect Invalidate() just redraws the
rows that were
> *previously* cached. I need to have the content
refetched -- the data has
> changed and the code needs to tell the ListView about
it.
> >
> >Perhaps the right approach is more along the lines
of RedrawItems()...but
> even there, it's not clear how code can find out how
many rows are in the
> ListView's cache, so it's difficult to know what
values to pass for the
> starting/ending indices. Same holds true for
OnCacheVirtualItems.
> >
> >On the select/focus issue: I thought I read
somewhere that this won't
> work when in VirtualMode. Sorry, I can't find the
reference. I don't have
> VS2005 here or I'd try it out myself.
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )