ProjectItems Interface

Contains ProjectItem objects, each representing items in the project.

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

Syntax

'Declaration
<GuidAttribute("8E2F1269-185E-43C7-8899-950AD2769CCF")> _
Public Interface ProjectItems _
    Inherits IEnumerable
'Usage
Dim instance As ProjectItems
[GuidAttribute("8E2F1269-185E-43C7-8899-950AD2769CCF")]
public interface ProjectItems : IEnumerable
[GuidAttribute(L"8E2F1269-185E-43C7-8899-950AD2769CCF")]
public interface class ProjectItems : IEnumerable
public interface ProjectItems extends IEnumerable

Remarks

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 Visual Studio .NET 2003 and Visual Studio 2005, special handling for the Project.ProjectItems collection for Visual C++ is no longer required. That is, while the Visual C++ ProjectItems collection previously stored all Visual C++ 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++ 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

Examples

' Before running, create a new project or open an existing project.
Sub ListProj()
   Dim proj As Project = DTE.ActiveSolutionProjects(0)
   Dim win As Window = _
     DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
   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
   Next
End Sub

See Also

Reference

ProjectItems Members

EnvDTE Namespace

Other Resources

Controlling Projects and Solutions

How to: Compile and Run the Automation Object Model Code Examples