Selected Property (ActiveX Controls)

       

Returns or sets a value that determines if an object is selected. For a ListItem object, the Selected property does not set the SelectedItem property, and thus does not cause the object to be selected. It only returns a value indicating whether the ListItem object has already been selected by other means.

Syntax

object.Selected [ = boolean]

The Selected property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
boolean A Boolean expression that determines if an object is selected.

Remarks

Use the Selected property to programmatically select a specific Node or Tab object. Once you have selected an object in this manner, you can perform various operations on it, such as setting properties and invoking methods.

To select a specific Node object, you must refer to it by the value of either its Index property or its Key property. The following example selects a specific Node object in a TreeView control:

Private Sub Command1_Click()
   TreeView1.Nodes(3).Selected = True ' Selects an object.
   ' Use the SelectedItem property to get a reference to the object.
   TreeView1.SelectedItem.Text = "Changed Text"
End Sub

In the ListView control, the SelectedItem property always refers to the first selected item. Therefore, if multiple items are selected, you must iterate through all of the items, checking each item's Selected property.

Note   Instead of using the Selected property to programmatically select a ListItem object, use the Set statement with the SelectedItem property, as follows:

Set ListView1.SelectedItem = ListView1.ListItems(1)