SelectedItem

This property returns a reference to a selected ListItem, Node, or Tab object.

Syntax

object.SelectedItem

Parameters

object
Object expression that evaluates to a ListItem, Node, or Tab object, as well as a ListView, TabStrip, or TreeView control.

Remarks

The SelectedItem property returns a reference to an object that can be used to set properties and invoke methods on the selected object. This property typically is used to return a reference to a ListItem, Node, or Tab or object that the user has clicked or selected. The following code example shows how to use this reference to validate an object before enabling any further action.

Command1_Click()
    ' If the selected object is not the root, then remove the Node.
    If TreeView1.SelectedItem.Index <> 1 Then
        Treeview1.Nodes.Remove TreeView1.SelectedItem.Index
    End If
End Sub

The following code example shows how to use the Set statement with the SelectedItem property in order to programmatically select a Node object.

Set TreeView1.SelectedItem = TreeView1.Nodes(1)

The following code example shows how to use the Set statement with the SelectedItem property in order to programmatically select a SelectedItem object.

Set ListView1.SelectedItem = ListView1.ListItems(1)