Export (0) Print
Expand All

ListView.CacheVirtualItems Event

Occurs when the contents of the display area for a ListView in virtual mode has changed, and the ListView determines that a new range of items is needed.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Event CacheVirtualItems As CacheVirtualItemsEventHandler

This event only occurs when VirtualMode is true. Handling this event allows the ListView to update the item information held in the cache so that it is readily available. This can improve performance on large lists, or lists whose items are expensive to calculate.

For more information about handling events, see Handling and Raising Events.

The following code example demonstrates the use of this member. In the example, the event handler checks to make sure a cache refresh is really necessary, and then rebuilds the cache. This code example is part of a larger example provided for the VirtualMode property.

'Manages the cache.  ListView calls this when it might need a  
'cache refresh. 
Private Sub listView1_CacheVirtualItems(ByVal sender As Object, ByVal e As CacheVirtualItemsEventArgs) Handles listView1.CacheVirtualItems
    'We've gotten a request to refresh the cache. 
    'First check if it's really neccesary. 
    If Not (myCache Is Nothing) AndAlso e.StartIndex >= firstItem AndAlso e.EndIndex <= firstItem + myCache.Length Then 
        'If the newly requested cache is a subset of the old cache,  
        'no need to rebuild everything, so do nothing. 
        Return 
    End If 

    'Now we need to rebuild the cache.
    firstItem = e.StartIndex
    Dim length As Integer = e.EndIndex - e.StartIndex + 1 'indexes are inclusive
    myCache = New ListViewItem(length) {}

    'Fill the cache with the appropriate ListViewItems. 
    Dim x As Integer = 0
    Dim i As Integer 
    For i = 0 To length
        x = (i + firstItem) * (i + firstItem)
        myCache(i) = New ListViewItem(x.ToString())
    Next i

End Sub

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft