Freigeben über


SelectedItems.Item(Object) Method

Definition

Returns a SelectedItem object in the SelectedItems collection.

public:
 EnvDTE::SelectedItem ^ Item(System::Object ^ index);
public:
 EnvDTE::SelectedItem ^ Item(Platform::Object ^ index);
EnvDTE::SelectedItem Item(winrt::Windows::Foundation::IInspectable const & index);
[System.Runtime.InteropServices.DispId(0)]
public EnvDTE.SelectedItem Item (object index);
[<System.Runtime.InteropServices.DispId(0)>]
abstract member Item : obj -> EnvDTE.SelectedItem
Public Function Item (index As Object) As SelectedItem

Parameters

index
Object

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

Returns

A SelectedItem object.

Attributes

Examples

public void CodeExample(DTE2 dte)  
{    
    try  
    {  
        // 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;  
        }  
        MessageBox.Show(msg);  
    }  
    catch(Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}  

Remarks

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.

Applies to