Export (0) Print
Expand All

ProjectItems Collection

Visual Studio .NET 2003

Contains ProjectItem objects, each representing items in the project.





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


This collection consists of a hierarchical (nested) structure of cascading ProjectItems collections that represent items in each project.

Reference this collection using Solution.Item().ProjectItems.

Note   In newer versions of Visual Studio .NET, special handling for the Project.ProjectItems collection for Visual C++ ® .NET is no longer required. That is, while the Visual C++ ® .NET ProjectItems collection previously stored all Visual C++ ® .NET project files in a flat list, now the files are stored hierarchically as they are in the other programming languages.
Since this change can affect your existing code, there is a way to emulate the old behavior in the new project-specific object model when trying to index the Project.ProjectItems collection to determine whether or not a file is in the project. The primary difference is that you can now return to the DTE object model by calling .Object on a Visual C++ ® .NET object.
Dim proj as VCProject = DTE.ActiveSolutionProjects(0).Object
Dim fileColl as IVCCollection = proj.Files
Dim file as VCFile = fileColl.Item("MyFile.cpp")
Dim projItem as ProjectItem = file.Object


Namespace: EnvDTE

File: dte.tlb


' Before running, create a new project or open an existing project.
Sub ListProj()
   Dim proj As Project = DTE.ActiveSolutionProjects(0)
   Dim win As Window = _
   ListProjAux(proj.ProjectItems(), 0)
End Sub

Sub ListProjAux(ByVal projitems As ProjectItems, ByVal Level As Integer)
   Dim projitem As ProjectItem
   For Each projitem In projitems
      MsgBox("Project item: " & projitem.Name, Level)
      ' Recurse if the project item has sub-items...
      Dim projitems2 As ProjectItems
      projitems2 = projitem.ProjectItems
      Dim notsubcoll As Boolean = projitems2 Is Nothing
      If Not notsubcoll Then
         ListProjAux(projitems2, Level + 1)
      End If
End Sub

See Also

Project Object | Projects Collection | ProjectItem Object

Properties, Methods, and Events

© 2014 Microsoft