ColumnHeader(s)

Description

The ColumnHeaders collection contains one or more ColumnHeader objects

A ColumnHeader is an item in a ListView control that contains heading text.

You can view ColumnHeader objects in Report view only.

With a ColumnHeader object, a user can:
● Click it to trigger the ColumnClick event and sort the items based on that data item
● Grab the object's right border and drag it to adjust the width of the column
● Hide ColumnHeader objects in Report view

There is always one column in the ListView control, which is Column 1. This column contains the actual ListItem objects; not their subitems. The second column (Column 2) contains subitems. Therefore, you always have one more ColumnHeader than subitems and the ListItem's SubItems property is a 1-based array of size ColumnHeaders.Count - 1.

The number of ColumnHeaders determines the number of subitems each ListItem in the control can have. When you delete a ColumnHeader, all of the subitems associated with the column are also deleted, and each ListItem's subitem array shifts to update the indices of the ColumnHeader, causing the remaining column headers' SubItemIndex properties to change.

Columnheaders Collection Properties and Methods

Property

Description

Count

(read-only) The total number of ColumnHeaders in the collection

Item (Index)

Returns a specific member of the collection (either by position or by key).

Because Item is the default property, the following lines are equivalent :
Print MyCollection(1)
Print MyCollection.Item(1)

Method

Description

Add

Parameters: [Index], [Key], [Text], [Width], [Alignment], [Icon]

Adds a ColumnHeader to a ColumnHeaders collection in a ListView control

Index

(optional) An integer specifying the position where you want to insert the ColumnHeader. If not specified, the ColumnHeader is added to the end of the ColumnHeaders collection.

Key

(optional) A unique string that identifies the ColumnHeader, Use this value to retrieve a specific ColumnHeader. An error occurs if the key is not unique.

Text

(optional) A string that appears in the ColumnHeader

Width

(optional) A numeric expression specifying the width of the object using the scale units of the control's container

Alignment

(optional). An integer that determines the alignment of text in the ColumnHeader. See the Alignment property above.

Icon

(optional). The key or index property of a ListImage object. The ColumnHeaderIcons property of the ListView must be set to the ImageList control containing the ListImage object(s).

Clear

Removes all ColumnHeaders in the collection

Remove

Parameters: Index

Removes a specific ColumnHeader. Index is an integer or string that uniquely identifies the ColumnHeader. Use an integer to specify the value of the Index property; use a string to specify the value of the Key property.

Individual Columnheader Properties

Property

Description

Alignment

0

Text in the ColumnHeader is left-aligned (default)

1

Text in the ColumnHeader is right-aligned

2

Text in the ColumnHeader is centered

The first column in a ListView control must be left-aligned !

Icon

Returns or sets an icon to be displayed in the ColumnHeader. The Icon property can be set to the Key or Index property of a ListImage object.
The ColumnHeaderIcons property of the ListView must be set to the ImageList control containing the ListImage object(s).

Index

(read-only) An integer that uniquely identifies a ColumnHeader in the collection. The index is set by default to the order of the creation of objects in a collection. The index for the first object in a collection will always be 1

Key

A string that uniquely identifies a ColumnHeader in the collection

Left

(read-only) The distance from the left edge of the ListView control

Position

Returns or sets the position of a ColumnHeader object. The integer can be any number from 1 to n, where n is the number of ColumnHeaders.
Use this property to rearrange the order of columns

SubItemIndex

(read-only) The index of the subitem associated with a ColumnHeader.

SubItems are arrays of strings representing the ListItem object's data when displayed in Report view. The first ColumnHeader always has a SubItemIndex set to 0 because the small icon and the ListItem's text always appear in the first column and are considered ListItem objects rather than subitems. The number of ColumnHeaders dictates the number of subitems. There is always exactly one more ColumnHeader than there are SubItems

Text

Returns or sets the text to be displayed in the ColumnHeader