# ListView class
{: .no_toc }

A **ListView** shows a list of items as large icons, small icons, a list, tiles or a report with a column for each part of an item. The user selects items, checks them, edits their labels, sorts the report by a column and drags items; the program can show the items in groups, or supply them as they are shown.

![A list view in the report view with check boxes and grid lines, under the columns Name, Size, aligned to the right, and Type. The arrow over Name shows the list sorted by it from A to Z. Beach.jpg and Notes.txt are checked, and the whole row of Notes.txt is selected.](/Reference/Contributed/VBCCR18/ListView/Images/ListView.png){:width="332" height="134"}

```tb check_build check_run arch=win32,win64
With ListView1
    .View = LvwViewReport
    .ColumnHeaders.Add , , "Name"
    .ColumnHeaders.Add , , "Size", , LvwColumnHeaderAlignmentRight
    .ListItems.Add(, "r", "readme.txt").SubItems(1) = "2 KB"
    .ListItems.Add(, "n", "notes.txt").SubItems(1) = "11 KB"
    .Sorted = True                          ' by the first column, from A to Z
    Debug.Print .ListItems(1).Text; " "; .ListItems(1).SubItems(1)
    Debug.Print .ListItems("r").Index
End With
' Output:
' notes.txt 11 KB
'  2
```

The control stands in place of the ListView of the Microsoft common controls (`MSCOMCTL.OCX`). The [WinNativeCommonCtls](/tB/Packages/WinNativeCommonCtls/ListView/index.md) package has a **ListView** too. This one adds the tile view, [groups](/tB/Packages/Contributed/VBCCR18/ListView/Groups.md), work areas, a [virtual mode](/tB/Packages/Contributed/VBCCR18/ListView/VirtualMode.md) for lists too long to hold, check boxes, filters and split buttons in the column headers, a background picture, insertion marks for drag and drop, and an event for each change of an item's selection, focus or check box.

Of the [common members](/tB/Packages/Contributed/VBCCR18/Common.md), the control has all of them: those under [Name and place](/tB/Packages/Contributed/VBCCR18/Common.md#name-and-place), [Window handles](/tB/Packages/Contributed/VBCCR18/Common.md#window-handles), [Font and visual styles](/tB/Packages/Contributed/VBCCR18/Common.md#font-and-visual-styles), [Mouse](/tB/Packages/Contributed/VBCCR18/Common.md#mouse), [Keyboard and focus](/tB/Packages/Contributed/VBCCR18/Common.md#keyboard-and-focus), [Dragging the control](/tB/Packages/Contributed/VBCCR18/Common.md#dragging-the-control), [OLE drag and drop](/tB/Packages/Contributed/VBCCR18/Common.md#ole-drag-and-drop) and [Right-to-left](/tB/Packages/Contributed/VBCCR18/Common.md#right-to-left), **RightToLeftLayout** included. [Drag and Drop](/tB/Packages/Contributed/VBCCR18/ListView/DragAndDrop.md) says what the control does of its own with **OLEDrag** and **OLEStartDrag**.

* TOC
{:toc}

## Topics

The members of the control are on these pages, by what they do:

- [Views and Icons](/tB/Packages/Contributed/VBCCR18/ListView/Views.md) -- the five views, the image lists of the icons, the arrangement of the icons, work areas, scrolling and the size of the control
- [Items and Subitems](/tB/Packages/Contributed/VBCCR18/ListView/Items.md) -- the items, the texts of their columns, their tool tips, and the events of a click on an item
- [Selection and Check Boxes](/tB/Packages/Contributed/VBCCR18/ListView/Selection.md) -- the selected item, selecting several, check boxes, ghosted items and hot tracking
- [Columns](/tB/Packages/Contributed/VBCCR18/ListView/Columns.md) -- the columns of the report view and the header above them: sizing, moving, sort arrows, check boxes, split buttons and filters
- [Sorting and Searching](/tB/Packages/Contributed/VBCCR18/ListView/SortingAndSearching.md) -- sorting the items by a column, finding an item by its text or its place
- [Groups](/tB/Packages/Contributed/VBCCR18/ListView/Groups.md) -- the items shown in groups with headers, which the user can collapse
- [Editing Labels](/tB/Packages/Contributed/VBCCR18/ListView/LabelEditing.md) -- the user editing the text of an item in place
- [Virtual Mode](/tB/Packages/Contributed/VBCCR18/ListView/VirtualMode.md) -- a list whose items the program supplies when they are shown
- [Drag and Drop](/tB/Packages/Contributed/VBCCR18/ListView/DragAndDrop.md) -- dragging items, insertion marks and dropped files
- [Appearance](/tB/Packages/Contributed/VBCCR18/ListView/Appearance.md) -- colors, border, background picture and the look of Windows Explorer

The objects the control holds have pages of their own:

- [LvwListItems](/tB/Packages/Contributed/VBCCR18/ListView/LvwListItems.md) and [LvwListItem](/tB/Packages/Contributed/VBCCR18/ListView/LvwListItem.md) -- the items and one item
- [LvwListSubItems](/tB/Packages/Contributed/VBCCR18/ListView/LvwListSubItems.md) and [LvwListSubItem](/tB/Packages/Contributed/VBCCR18/ListView/LvwListSubItem.md) -- the subitems of an item and one subitem
- [LvwColumnHeaders](/tB/Packages/Contributed/VBCCR18/ListView/LvwColumnHeaders.md) and [LvwColumnHeader](/tB/Packages/Contributed/VBCCR18/ListView/LvwColumnHeader.md) -- the columns and one column
- [LvwGroups](/tB/Packages/Contributed/VBCCR18/ListView/LvwGroups.md) and [LvwGroup](/tB/Packages/Contributed/VBCCR18/ListView/LvwGroup.md) -- the groups and one group
- [LvwWorkAreas](/tB/Packages/Contributed/VBCCR18/ListView/LvwWorkAreas.md) and [LvwWorkArea](/tB/Packages/Contributed/VBCCR18/ListView/LvwWorkArea.md) -- the work areas and one work area
- [LvwVirtualListItems](/tB/Packages/Contributed/VBCCR18/ListView/LvwVirtualListItems.md) and [LvwVirtualListItem](/tB/Packages/Contributed/VBCCR18/ListView/LvwVirtualListItem.md) -- the items of a virtual list and one item

## Numbers and keys

Items, subitems, columns and groups are numbered from 1. A number is a place: it changes when an object is added or removed in front of it, and the number of an item also changes when the items are sorted. A key is a string of the program's own that stays with its object, and capital and small letters in it are the same. Each collection of these has **Add**, **Item**, **Exists**, **Count**, **Remove** and **Clear**, and a program goes through it with **For Each**.

## Filling a long list

While [**Redraw**](#redraw) is **False** the control does not draw itself, so a program that adds many items sets it to **False** first and to **True** at the end. The items are there all the time; only the drawing waits.

```tb check_build check_run arch=win32,win64
Dim i As Long
ListView1.Redraw = False
For i = 1 To 500
    ListView1.ListItems.Add , , "Item " & i
Next
ListView1.Redraw = True
Debug.Print ListView1.ListItems.Count
' Output:
'  500
```

Properties
----------

### Redraw
{: .no_toc }

Whether the control draws itself when its items change. **Boolean**. Default: **True**. Setting it to **True** draws the control again at once.

Events
------

### ContextMenu
{: .no_toc }

Raised when the user asks for a shortcut menu over the control: with the right mouse button, with Shift+F10, or with the menu key.

Syntax: *object*\_**ContextMenu**( **ByVal** *X* **As Single**, **ByVal** *Y* **As Single** )

*X*, *Y*
: Where the pointer is, measured from the control's top left corner in the scale units of its container. Both are -1 when the user pressed a key: the program then shows the menu at the selected item, or at the control.

```tb check_build
Private Sub ListView1_ContextMenu(ByVal X As Single, ByVal Y As Single)
    If X = -1 And Y = -1 Then
        Debug.Print "Menu from the keyboard"
    Else
        Debug.Print "Menu at"; X; Y
    End If
End Sub
```

## See Also

- [Common members](/tB/Packages/Contributed/VBCCR18/Common.md) -- the members this control shares with the package's other controls
- [ImageList](/tB/Packages/Contributed/VBCCR18/ImageList/index.md) control -- the pictures of the items, the columns and the groups
- [ListView](/tB/Packages/WinNativeCommonCtls/ListView/index.md) -- the control of the same name in the WinNativeCommonCtls package
