Condividi tramite


Metodo TaskItems2.Item (Object)

Restituisce un membro indicizzato di un insieme TaskItems.

Spazio dei nomi:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Sintassi

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

Parametri

  • index
    Tipo: System.Object
    Obbligatorio.L'indice dell'elemento da restituire.

Valore restituito

Tipo: EnvDTE.TaskItem
Un oggetto TaskItem.

Implementa

TaskItems.Item(Object)

Note

Il valore passato a Index è un intero corrispondente a un indice di un oggetto nel relativo insieme. Per molti oggetti, tuttavia, il valore di Index può essere anche un valore stringa che corrisponde a un oggetto dell'insieme. Il valore esatto accettato da Item, tuttavia, dipende dall'insieme e dalla relativa implementazione.

Il metodo Item genera un'eccezione ArgumentException se l'insieme non riesce a trovare l'oggetto corrispondente al valore di indice.

Esempi

In questo esempio vengono aggiunti due elementi all'Elenco attività e ne vengono visualizzate alcune proprietà Item specifiche in finestre di messaggio. Per ulteriori informazioni sulla modalità di esecuzione di questo esempio come componente aggiuntivo, vedere Procedura: compilare ed eseguire gli esempi di codice del modello a oggetti di automazione.

Imports EnvDTE
Imports EnvDTE80
Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    TaskItems2ItemExample(_applicationObject)
End Sub
Sub TaskItems2ItemExample(ByVal dte As DTE2)
    Dim win As Window = _
     _applicationObject.Windows.Item(Constants.vsWindowKindTaskList)
    Dim TL As TaskList = CType(win.Object, TaskList)
    Dim TLItem As TaskItem
    Dim TLItems As TaskItems2
    TLItems = CType(TL.TaskItems, TaskItems2)
    ' Add a couple of tasks to the Task List using Add2.
    TLItem = TLItems.Add2(" ", " ", "Test task 1." _
    , vsTaskPriority.vsTaskPriorityHigh,  _
    vsTaskIcon.vsTaskIconUser, True, , 10, , , False)
     TLItem = TLItems.Add2(" ", " ", "Test task 2." _
    , vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment, _
     , , 20, , , False)
    ' List the total number of task list items after adding the new 
    ' task items.
    MsgBox("Task Item 1 description: " & TLItems.Item(2).Description)
    MsgBox("Task Item 2 category: "  _
    & TLItems.Item(1).Category.ToString())
    MsgBox("Total number of task items: " & TLItems.Count)
    ' Remove the second task item.
    ' The items list in reverse numeric order.
    MsgBox("Deleting the second task item")
    TLItems.Item(1).Delete()
    MsgBox("Total number of task items: " & TLItems.Count)
End Sub
using EnvDTE;
using EnvDTE80;
using System.Windows.Forms;
public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    TaskItemsItemExample(_applicationObject);
}
public void TaskItems2ItemExample(DTE2 dte)
{
    Window2 win =
 (Window2)_applicationObject.Windows.Item
(Constants.vsWindowKindTaskList);
    TaskList TL = (TaskList)win.Object;
    TaskItem TLItem;
    TaskItems2 TLItems;
    TLItems = (TaskItems2)TL.TaskItems;
    // Add a couple of tasks to the Task List.
    TLItem = TLItems.Add2("MyTask", "MyTask1", "Test task 1.", 
1, vsTaskIcon.vsTaskIconUser, true,null,10,true,true,true);
    TLItem = TLItems.Add2("MyTask", "MyTask1", "Test task 2.", 
2, vsTaskIcon.vsTaskIconComment, true, null, 20, true, true,false);
    // List the total number of task list items after adding the new
    // task items.
    MessageBox.Show("Task Item 1 description: " 
+ TLItems.Item(2).Description);
    MessageBox.Show("Task Item 2 category: " 
+ TLItems.Item(1).Category.ToString());
    MessageBox.Show("Total number of task items: " 
+ TLItems.Count.ToString());
    // Remove the second task item.
    // The items list in reverse numeric order.
    MessageBox.Show("Deleting the second task item");
    TLItems.Item(1).Delete();
    MessageBox.Show("Total number of task items: " + TLItems.Count);
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

TaskItems2 Interfaccia

Overload Item

Spazio dei nomi EnvDTE80