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 

이벤트 유형

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 보관된 항목 정보를 쉽게 사용할 수 있도록 업데이트할 수 있습니다. 이렇게 하면 큰 목록 또는 계산 비용이 많이 드는 항목이 있는 목록의 성능이 향상될 수 있습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

적용 대상