TvwSelectedNodes class

The collection of the selected nodes of a TreeView whose MultiSelect is not TvwMultiSelectNone, which its SelectedNodes property returns. Its items are TvwNode objects, numbered from 1, the node selected last first. It has no keys. A program cannot make a TvwSelectedNodes object with New.

Dim Node As TvwNode
TreeView1.MultiSelect = TvwMultiSelectAll
TreeView1.Nodes.Add , , "a", "A"
TreeView1.Nodes.Add , , "b", "B"
TreeView1.Nodes("a").Selected = True
TreeView1.Nodes("b").Selected = True
For Each Node In TreeView1.SelectedNodes
    Debug.Print Node.Text
Next
Debug.Print TreeView1.SelectedNodes.Count
' Output:
'  B
'  A
'  2

The collection changes as the selection does, and a program goes through it with For Each or by number from 1 to Count. The tree’s SelectedItem is the node that has the focus, which is not always the first of the collection: a node that the program selects with Selected joins the collection as the first, and the focus stays where it was. See Selecting several nodes.

Properties

Count

The number of selected nodes. Long, read-only.

Item

Returns one selected node. It is the default member, so TreeView1.SelectedNodes(1) is TreeView1.SelectedNodes.Item(1).

Syntax: object.Item( Index ) As TvwNode

Index
required A Long: the number of the node, from 1 to Count.

A number outside that range raises run-time error 35600, Index out of bounds.

Methods

Exists

Returns whether the collection has an item of a number, so that a program can ask before Item raises an error.

Syntax: object.Exists( Index ) As Boolean

Index
required A Long: the number to look for.

See Also