This documentation is archived and is not being maintained.

SelectedItem Interface

Represents selected project(s) or project item(s) in the Visual Studio integrated development environment (IDE).

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

public interface SelectedItem

The SelectedItem type exposes the following members.

Public propertyCollectionGets the SelectedItems collection containing the SelectedItem object supporting this.
Public propertyDTEGets the top-level extensibility object.
Public propertyInfoInfrastructure. Microsoft Internal Use Only.
Public propertyInfoCountInfrastructure. Microsoft Internal Use Only.
Public propertyNameGets the name of the SelectedItem object.
Public propertyProjectGets the Project object associated with the SelectedItem object.
Public propertyProjectItemGets the ProjectItem object associated with the given object.

Sub SelectionContainerSelectedItemExample()
   Dim SelItems As SelectedItems
   Dim SelItemObj As SelectedItem
   Dim SelContain As SelectionContainer
   Dim SelItem As SelectedItem
   Dim NameStr As String

   SelItems = DTE.SelectedItems
   ' List the number of items selected.
   If SelItems.MultiSelect = True Then
      MsgBox("You have " & SelItems.Count & " items selected in _
        Solution Explorer.")
   End If

   ' Set a reference to the first selected item.
   SelItemObj = SelItems.Item(1)
   ' List the names of the project or project items under the selected 
   ' item.
   For Each SelItem In SelItemObj.Collection
      NameStr = NameStr & SelItem.Name
      If TypeOf SelItem.Project Is Project Then
         NameStr = NameStr & " Project-" & SelItem.Project.Name & vbCrLf
         If TypeOf SelItem.ProjectItem Is ProjectItem Then
             NameStr = NameStr & SelItem.ProjectItem.FileNames(1) & vbCrLf
         End If
      End If
   MsgBox("You selected: " & NameStr)
End Sub