This documentation is archived and is not being maintained.

SelectedItem Object

Visual Studio .NET 2003

Represents selected project(s) or project item(s) in the Visual Studio .NET IDE.

DTE

   SelectedItems

      SelectedItem

[Visual Basic .NET]
Public Interface SelectedItem
    Inherits IDispatch
[Visual Basic 6]
Class SelectedItem
[C++]
interface SelectedItem : IDispatch
[C#]
public interface SelectedItem : IDispatch
[JScript .NET]
public interface SelectedItem extends IDispatch

Requirements

Namespace: EnvDTE

File: dte.olb

Example

This example lists information about items selected in Solution Explorer. To run this example, first create a project and select one or more items in the project (add more items if necessary).

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
      Else
         If TypeOf SelItem.ProjectItem Is ProjectItem Then
             NameStr = NameStr & SelItem.ProjectItem.FileNames(1) & vbCrLf
         End If
      End If
   Next
   MsgBox("You selected: " & NameStr)
End Sub

See Also

Properties, Methods, and Events | SelectedItems Collection | SelectedItems Property (General Extensibility)

Show: