ListView.CacheVirtualItems Событие

Определение

Происходит в том случае, когда было изменено содержимое отображаемой области элемента управления ListView, находящегося в виртуальном режиме, и элементом управления ListView определено, что требуется новый диапазон элементов.

public:
 event System::Windows::Forms::CacheVirtualItemsEventHandler ^ CacheVirtualItems;
public event System.Windows.Forms.CacheVirtualItemsEventHandler CacheVirtualItems;
public event System.Windows.Forms.CacheVirtualItemsEventHandler? CacheVirtualItems;
member this.CacheVirtualItems : System.Windows.Forms.CacheVirtualItemsEventHandler 
Public Custom Event CacheVirtualItems As CacheVirtualItemsEventHandler 

Тип события

Примеры

В следующем примере кода показано использование этого элемента. В этом примере обработчик событий проверяет необходимость обновления кэша, а затем перестраивает кэш. Этот пример кода является частью более крупного примера, предоставленного VirtualMode для свойства .

//Manages the cache.  ListView calls this when it might need a 
//cache refresh.
void listView1_CacheVirtualItems(object sender, CacheVirtualItemsEventArgs e)
{
    //We've gotten a request to refresh the cache.
    //First check if it's really neccesary.
    if (myCache != null && e.StartIndex >= firstItem && e.EndIndex <= firstItem + myCache.Length)
    {
        //If the newly requested cache is a subset of the old cache, 
        //no need to rebuild everything, so do nothing.
        return;
    }

    //Now we need to rebuild the cache.
    firstItem = e.StartIndex;
    int length = e.EndIndex - e.StartIndex + 1; //indexes are inclusive
    myCache = new ListViewItem[length];
    
    //Fill the cache with the appropriate ListViewItems.
    int x = 0;
    for (int i = 0; i < length; i++)
    {
        x = (i + firstItem) * (i + firstItem);
        myCache[i] = new ListViewItem(x.ToString());
    }
}
'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

Комментарии

Это событие возникает только в том случае, если VirtualMode имеет значение true. Обработка этого события позволяет объекту ListView обновлять сведения об элементах, хранящиеся в кэше, чтобы они были доступны. Это может повысить производительность больших списков или списков, элементы которых являются дорогостоящими для вычисления.

Дополнительные сведения об обработке событий см. в разделе Обработка и вызов событий.

Применяется к