TaskItems2.Item 方法
傳回 TaskItems 集合的索引成員。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
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
參數
index
類型:Object必要項。 所要傳回項目的索引。
傳回值
類型:TaskItem
TaskItem 物件。
備註
傳遞給 Index 的值是整數,也就是物件在集合中的索引。 然而對許多物件而言,Index 值也可以是等於集合中之物件的字串值。 但是,Item 接受的實際值,會視集合及其實作而有所不同。
如果集合無法找到對應索引值的物件,Item 方法就會擲回 ArgumentException 例外狀況。
範例
這個範例會將兩個工作項目加入至工作清單中,並在訊息視窗中顯示這兩個項目的某些 Item 特定屬性。 如需如何像執行增益集一般,執行這個範例的詳細資訊,請參閱 如何:編譯和執行 Automation 物件模型程式碼範例。
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);
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。