LvwGroups class

The collection of the groups of a ListView, which its Groups property returns. Its items are LvwGroup objects, numbered from 1, and a group can have a key as well.

With ListView1.Groups
    .Add , "b", "Beta"
    .Add , "c", "Gamma"
    .Add , "a", "Alpha"
    .Sorted = True                          ' by the headers' texts
    Debug.Print .Item("a").Position; .Item("b").Position; .Item("c").Position
    Debug.Print .Item(1).Header; .Item(1).Index
End With
' Output:
'  1  2  3
' Beta 1

A program goes through the groups with For Each, or by number from 1 to Count. It cannot make an LvwGroups object with New. The number of a group, its Index, is its place in the collection; its place on the screen is its Position, which sorting changes.

Properties

Count

The number of groups. Long, read-only.

Item

Returns one group. It is the default member, so ListView1.Groups("a") is ListView1.Groups.Item("a").

Syntax: object.Item( Index ) As LvwGroup

Index
required The number of the group, from 1 to Count, or its key as a String, in which capital and small letters are the same.

A number outside that range raises run-time error 9, and a key that no group has raises run-time error 5. Exists asks without an error.

Sorted

Whether the groups are shown in the order of their Header texts. Boolean. Default: False. True sorts them at once, and a group added while it is True goes to its place. Sorting changes the groups’ Position, not their numbers.

SortOrder

Whether the groups are sorted in ascending or descending order. A member of LvwSortOrderConstants. Default: LvwSortOrderAscending. Another value raises run-time error 380.

SortType

How two headers compare when the groups are sorted. A member of LvwSortTypeConstants. Default: LvwSortTypeBinary. Another value raises run-time error 380.

Methods

Add

Adds a group and returns its LvwGroup.

Syntax: object.Add( [ Index ] [, Key ] [, Header ] [, HeaderAlignment ] [, Footer ] [, FooterAlignment ] ) As LvwGroup

Index
optional A Long: the number the new group gets, and its place on the screen. The groups from that number on move up by one. Without it, or with 0, the group goes after the last one.
Key
optional A String by which the program can name the group.
Header
optional A String: the text of the group’s header.
HeaderAlignment
optional A member of LvwGroupHeaderAlignmentConstants. The default is LvwGroupHeaderAlignmentLeft.
Footer
optional A String: the text of the group’s footer.
FooterAlignment
optional A member of LvwGroupFooterAlignmentConstants. The default is LvwGroupFooterAlignmentLeft.

A negative Index, and one greater than Count + 1, raises run-time error 35600. A Key that another group has raises run-time error 457.

Clear

Removes every group. GroupView stays as it was.

Syntax: object.Clear

Exists

Returns whether the collection has a group of a number or a key.

Syntax: object.Exists( Index ) As Boolean

Index
required The number or the key to look for.

Remove

Removes one group. The groups after it move down by one.

Syntax: object.Remove Index

Index
required The number or the key of the group. One that the collection does not have raises the error that Item raises for it.

See Also