LvwColumnHeader class

One column of a ListView and its header: its text, its width, the alignment of its texts, its place, and the sort arrow, check box, split button and filter of its header. A program gets one from the LvwColumnHeaders collection and its Add method, and from the control’s events that name a column.

Dim Size As LvwColumnHeader
With ListView1
    .View = LvwViewReport
    .ColumnHeaders.Add , "name", "Name"
    Set Size = .ColumnHeaders.Add(, "size", "Size")
    Size.Alignment = LvwColumnHeaderAlignmentRight
    Size.SortArrow = LvwColumnHeaderSortArrowUp
    Debug.Print Size.Index; Size.Position; Size.SubItemIndex; Size.Text
End With
' Output:
'  2  2  1 Size

A program cannot make an LvwColumnHeader object with New.

Filters

While the control’s UseColumnFilterBar is True, each header has a box under its text in which the user types a filter, a text or a whole number by the column’s FilterType. FilterValue reads and sets it, and is Null while the box is empty.

With ListView1
    .View = LvwViewReport
    .UseColumnFilterBar = True
    .ColumnHeaders.Add , , "Size"
    .ColumnHeaders(1).FilterType = LvwColumnHeaderFilterTypeNumber
    Debug.Print IsNull(.ColumnHeaders(1).FilterValue)
    .ColumnHeaders(1).FilterValue = 42
    Debug.Print .ColumnHeaders(1).FilterValue
    .ColumnHeaders(1).ClearFilter
    Debug.Print IsNull(.ColumnHeaders(1).FilterValue)
End With
' Output:
' True
'  42
' True

Properties

Alignment

How the texts of the column are aligned. A member of LvwColumnHeaderAlignmentConstants. Another value raises run-time error 380.

Bold

Whether the header’s text is drawn in bold. Boolean. Default: False.

CheckBox

Whether the header shows a check box, while the control’s AllowColumnCheckboxes is True. Boolean. Default: False. False also unchecks it. It has an effect when the program has visual styles.

Checked

Whether the header’s check box is checked. Boolean. Default: False. A change raises ColumnCheck. A column whose CheckBox is False stays unchecked.

FilterType

Whether the column’s filter is a text or a whole number. A member of LvwColumnHeaderFilterTypeConstants. Default: LvwColumnHeaderFilterTypeText. Another value raises run-time error 380. A change empties the filter.

FilterValue

The column’s filter. Variant: a String or a Long by FilterType, or Null while the filter is empty. An assignment takes a string for a text filter, and a number for a number filter, rounded to a whole one; Null or Empty empties the filter.

A value of another type raises run-time error 13.

ForeColor

The color of the header’s text. OLE_COLOR. Default: vbButtonText.

Icon

The number or the key of the header’s icon in the image list of ColumnHeaderIcons. Variant. 0 when the header has none. An assignment takes a number or a key, as Add does.

IconIndex

The number of the header’s icon in the image list, also when Icon names it by its key. Long, read-only.

IconOnRight

Whether the header’s icon is at the right of its text. Boolean. Default: False.

Index

The number of the column in the LvwColumnHeaders collection, from 1. Long, read-only.

Key

The column’s key in the LvwColumnHeaders collection. String. An assignment gives the column another key; an empty string takes the key away, and a key that another column has raises run-time error 457.

Left

The distance from the left edge of the header to the left edge of this column’s header, in the scale units of the control’s container. Single, read-only: an assignment raises run-time error 383.

Position

The place of the column among the others, from the left, from 1. Long. An assignment moves the column there. See The order of the columns.

A place less than 1 or greater than the number of columns raises run-time error 380.

Resizable

Whether the user can change the column’s width. Boolean. Default: True. The control’s ResizableColumnHeaders set to False fixes every column.

SortArrow

The sort arrow in the header. A member of LvwColumnHeaderSortArrowConstants. Default: LvwColumnHeaderSortArrowNone. Another value raises run-time error 380. Setting it does not sort the items; see Sorting by a click on a column.

SplitButton

Whether the header is a split button, with an arrow at its right that raises ColumnDropDown. Boolean. Default: False. It has an effect when the program has visual styles.

Tag

A value of the program’s own, which the control does not use. Variant: it holds a value of any type, an object included, which is assigned with Set. A new column has an empty string.

Text

The header’s text. String. It is the default member.

ToolTipText

The tip shown while the pointer rests on the header and the control’s ShowColumnTips is True. String. Default: empty.

ToolTipTextDropDown

The tip shown over the arrow of the header’s split button. String. Default: empty.

ToolTipTextFilterBtn

The tip shown over the filter button of the header. String. Default: empty.

Width

The width of the column, in the scale units of the control’s container. Single.

A negative width raises run-time error 380.

Methods

AutoSize

Makes the column as wide as its texts.

Syntax: object.AutoSize Value

Value
required A member of LvwColumnHeaderAutoSizeConstants: the widest text of the items, or of the items and the header. Another value raises run-time error 380.

ClearFilter

Empties the column’s filter.

Syntax: object.ClearFilter

EditFilter

Gives the focus to the column’s filter box, while the control’s UseColumnFilterBar is True, so that the user can type in it.

Syntax: object.EditFilter

SubItemIndex

Returns the number of the subitem the column shows: 0 for the items’ own texts, in the first column, 1 for the second column, and so on. Long.

Syntax: object.SubItemIndex( ) As Long

See Also