SelectedItems.Item Method (Object)


Returns a SelectedItem object in the SelectedItems collection.

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

SelectedItem Item(
	object index


Type: System.Object

Required. The index or name of the selected item to return.

Return Value

Type: EnvDTE.SelectedItem

A SelectedItem object.

The value passed to Index is either an integer equating to a SelectedItem object in the SelectedItems collection or a string value that equates to the name of a selected item in the collection.

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

public void CodeExample(DTE2 dte)
        // Open project and select one or more items in 
        // Solution Explorer before running this example.
        SelectedItem selItem;
        string msg = "";
        if (dte.SelectedItems.Count > 0)
            selItem = dte.SelectedItems.Item(1);
            msg = "The first selected item is " + selItem.Name;
    catch(Exception ex)
Return to top