Share via


Documents.Item Method

Returns an indexed member of a Documents collection.

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

Syntax

'Declaration
Function Item ( _
    index As Object _
) As Document
Document Item(
    Object index
)
Document^ Item(
    [InAttribute] Object^ index
)
abstract Item : 
        index:Object -> Document 
function Item(
    index : Object
) : Document

Parameters

  • index
    Type: System.Object
    Required. The index of the item to return.

Return Value

Type: EnvDTE.Document
A Document object.

Remarks

For most objects, the value passed to Index is an integer that is an index to an object in its collection. For many objects, though, the value of Index can also be a string value that equates to an object in the collection. The exact value that is accepted by Item, though, depends on the collection and its implementation.

The Item method throws a ArgumentException exception if the collection cannot find the object that corresponds to the index value.

Examples

Sub ItemExample(ByVal dte As DTE2)

    ' NOTE: This example requires a reference to the 
    '       System.Collections namespace.

    If MsgBox("Close all saved documents?", MsgBoxStyle.YesNo) = _
        MsgBoxResult.Yes Then
        ' Create a list of all saved documents.
        Dim docs As Documents = dte.Documents
        Dim savedDocs As New ArrayList

        Dim i As Integer
        For i = 1 To docs.Count
            If docs.Item(i).Saved Then
                savedDocs.Add(docs.Item(i))
            End If
        Next

        ' Close all saved documents.
        Dim doc As Document
        For Each doc In savedDocs
            doc.Close(vsSaveChanges.vsSaveChangesNo)
        Next
    End If

End Sub
public void ItemExample(DTE2 dte)
{
    // NOTE: This example requires a reference to the 
    //       System.Collections namespace.

    if (MessageBox.Show("Close all saved documents?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        // Create a list of all saved documents.
        Documents docs = dte.Documents;
        ArrayList savedDocs = new ArrayList(); 

        for (int i = 1; i <= docs.Count; i++)
        {
            if (docs.Item(i).Saved)
                savedDocs.Add(docs.Item(i));
        }

        // Close all saved documents.
        foreach (Document doc in savedDocs)
            doc.Close(vsSaveChanges.vsSaveChangesNo);
    }
}

.NET Framework Security

See Also

Reference

Documents Interface

EnvDTE Namespace

Other Resources

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