Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining

SelectedItems Collection

Visual Studio .NET 2003

Contains SelectedItem objects, which represent selected projects or project items.



[Visual Basic .NET]
Public Interface SelectedItems
    Inherits IDispatch
[Visual Basic 6]
Class SelectedItems
interface SelectedItems : IDispatch
public interface SelectedItems : IDispatch
[JScript .NET]
public interface SelectedItems extends IDispatch


There is always a SelectedItems collection, even when there are no project items. For example, if Solution Explorer has focus and a project node is selected, then there is one SelectedItem Object. The selected item's Project Property refers to the selected project and its ProjectItem property is Null.


Namespace: EnvDTE

File: dte.olb


Sub SelectedItemsExample()
   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

See Also

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

© 2015 Microsoft