TaskItems2.Item(Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回 TaskItems 集合的一个索引成员。
public:
EnvDTE::TaskItem ^ Item(System::Object ^ index);
public:
EnvDTE::TaskItem ^ Item(Platform::Object ^ index);
EnvDTE::TaskItem Item(winrt::Windows::Foundation::IInspectable const & index);
[System.Runtime.InteropServices.DispId(0)]
public EnvDTE.TaskItem Item (object index);
[<System.Runtime.InteropServices.DispId(0)>]
abstract member Item : obj -> EnvDTE.TaskItem
Public Function Item (index As Object) As TaskItem
参数
- index
- Object
必需。 要返回的项的索引。
返回
TaskItem 对象。
实现
- 属性
示例
Imports EnvDTE
Imports EnvDTE80
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 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);
}
注解
传递给的值 Index 是一个整数,它是其集合中对象的索引。 但对于许多对象,的值 Index 还可以是一个字符串值,该值相当于集合中的对象。 但接受的确切值 Item 取决于集合及其实现。
Item ArgumentException 如果集合找不到与索引值对应的对象,则该方法将引发异常。