Virtual Mode

Shows a list that the ListView does not hold: the program says how many items there are, and gives the text, the icon and the other properties of each item when the control is about to show it.

' VirtualMode is True in the Properties window, and View is LvwViewReport.
Private Sub Form_Load()
    ListView1.ColumnHeaders.Add , , "Number"
    ListView1.ColumnHeaders.Add , , "Square"
    ListView1.VirtualItemCount = 1000000
End Sub

Private Sub ListView1_GetVirtualItem(ByVal ItemIndex As Long, ByVal SubItemIndex As Long, ByVal VirtualProperty As LvwVirtualPropertyConstants, Value As Variant)
    If VirtualProperty = LvwVirtualPropertyText Then
        If SubItemIndex = 0 Then Value = CStr(ItemIndex) Else Value = CStr(CDbl(ItemIndex) * ItemIndex)
    End If
End Sub

A list the program supplies

VirtualMode is set in the Properties window; at run time it is read-only. In virtual mode VirtualItemCount is the number of items, up to a hundred million, and the control raises GetVirtualItem for each property of each item it draws. It stores no items, so a program shows a list too long to add item by item, or one whose data is elsewhere, in a database or a file. CacheVirtualItems tells the program which items are about to be drawn, so that it can read them in one go, and VirtualDisabledInfos says which properties the control need not ask for.

An assignment to VirtualMode at run time raises run-time error 382. VirtualListItems, the items of a virtual list, raises run-time error 91 while the control is not in virtual mode.

What virtual mode changes

The control holds no items, no groups and no work areas: reading ListItems, Groups and WorkAreas raises run-time error 91, and VirtualListItems returns the items by number. The items are always arranged automatically; the tile view, Sorted, GroupView and an Arrange other than LvwArrangeNone raise run-time error 383, and FindSubItem, ResetForeColors and SelectedGroup raise run-time error 5.

An item that the control returns, such as its SelectedItem or the Item of an event, is an LvwListItem that knows its number alone. Its Index, Text, SubItems, Selected, Checked, Hot, Indentation, Visible, place and size can be read, its Selected, Hot, Left and Top set, and its EnsureVisible and CreateDragImage called; every other member raises run-time error 91.

Check boxes are the program’s to keep. When the user checks or unchecks an item, the control raises ItemCheck with the state the item is to have, and then asks GetVirtualItem for LvwVirtualPropertyChecked: the handler of ItemCheck stores the state where GetVirtualItem finds it.

Properties

VirtualDisabledInfos

The properties that the control does not ask for in GetVirtualItem, so that a list that has no icons, say, is drawn faster. A sum of members of LvwVirtualPropertyConstants. Default: 0, with which the control asks for all of them.

A negative value raises run-time error 380.

VirtualItemCount

The number of items of a virtual list. Long, from 0 to 100,000,000. Default: 0. A change keeps the list scrolled where it was. When the list gets its first items, the first one gets the focus, and is selected while AutoSelectFirstItem is True.

A number outside that range raises run-time error 380. While the control is not in virtual mode the number is kept and does nothing.

VirtualListItems

The items of a virtual list, as an LvwVirtualListItems collection. Read-only. While the control is not in virtual mode it raises run-time error 91.

VirtualMode

Whether the program supplies the items. Boolean. Default: False. It is set in the Properties window, where True also sets View from tile to icon, Arrange to LvwArrangeNone, and Sorted and GroupView to False. At run time it is read-only.

Events

CacheVirtualItems

Raised in virtual mode before the control draws a range of items.

Syntax: object_CacheVirtualItems( ByVal FromIndex As Long, ByVal ToIndex As Long )

FromIndex, ToIndex
The numbers of the first and the last item of the range, from 1.

FindVirtualItem

Raised in virtual mode when the control looks for an item by its text: when the user types the first letters of an item, and when the program calls FindItem.

Syntax: object_FindVirtualItem( ByVal StartIndex As Long, ByVal SearchText As String, ByVal Partial As Boolean, ByVal Wrap As Boolean, FoundIndex As Long )

StartIndex
The number of the item to start at.
SearchText
The text to find.
Partial
True when an item whose text starts with SearchText matches; False when the text must be SearchText.
Wrap
True when the search goes on from the first item after the last.
FoundIndex
Set by the handler: the number of the item found, from 1. 0, the value when the event is raised, means none.

GetVirtualItem

Raised in virtual mode when the control needs a property of an item or of a subitem.

Syntax: object_GetVirtualItem( ByVal ItemIndex As Long, ByVal SubItemIndex As Long, ByVal VirtualProperty As LvwVirtualPropertyConstants, Value As Variant )

ItemIndex
The number of the item, from 1.
SubItemIndex
The number of the subitem, or 0 for the item itself.
VirtualProperty
The property asked for, one member of LvwVirtualPropertyConstants.
Value
Set by the handler: the property’s value, of the type that member names. A handler that leaves it as it is gives the property its default: no text, no icon, and so on.

LvwVirtualPropertyConstants

The properties that GetVirtualItem asks for, and that VirtualDisabledInfos sums.

Member Value The handler gives
LvwVirtualPropertyText 1 the text of the item or of the subitem, a String
LvwVirtualPropertyIcon 2 the number or the key of the icon in Icons for the icon view, and in SmallIcons for the others; Empty for none
LvwVirtualPropertyIndentation 4 how far the item is moved to the right in the report view, in widths of a small icon, a Long
LvwVirtualPropertyToolTipText 8 the tool tip, a String, shown while ShowInfoTips is True
LvwVirtualPropertyBold 16 whether the text is bold, a Boolean
LvwVirtualPropertyForeColor 32 the color of the text, an OLE_COLOR; the control’s ForeColor when the event is raised
LvwVirtualPropertyChecked 64 whether the item’s check box is checked, a Boolean

See Also