Share via


Controlling the Task List

The Task List is represented in the Visual Studio .NET automation model by the following objects and collection.

Object Name Description
TaskList object Represents the Task List.
TaskItems collection Represents all of the tasks in the Task List.
TaskItem object Represents a single task item in the Task List.
TaskListEvents object Allows you to respond to events that occur in the Task List.

Using these objects and collections, you can:

  • Create a task item and add it to the Task List (Add method) or delete it from the Task List (Delete method).
  • Obtain items currently in the Task List (Select method).
  • Display a document associated with a Task Item (Navigate method).
  • Select a Task Item (Select method).
  • Respond when a Task Item is added, removed, modified, or selected (TaskAdded, TaskRemoved, TaskModified, and TaskNavigated methods.)

In addition to controlling the contents of the Task List, you can also control its characteristics such as width and height. For more information about this, see Changing Window Characteristics.

Task List Example

The following VSA example demonstrates how to reference and use the various members of the TaskList automation model. This example adds a couple of new tasks to the Task List, lists the number of tasks, and then deletes one. Before running the following example, display the Task List by pressing CTRL + ALT + K.

Sub TaskListExample()
   Dim win As Window = DTE.Windows.Item(Constants.vsWindowKindTaskList)
   Dim TL As TaskList = win.Object
   Dim TLItem As taskitem
        
   'Add a couple of tasks to the Task List.
   TLItem = TL.TaskItems.Add(" ", " ", "Test task 1.", vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser, True, , 10, , )
   TLItem = TL.TaskItems.Add(" ", " ", "Test task 2.", vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment, , , 20, , )

   'List the total number of task list items after adding the new 
   'task items.
   MsgBox("Task Item 1 description: " & TL.TaskItems.Item(2).Description)
   MsgBox("Total number of task items: " & TL.TaskItems.Count)

   'Remove the second task item. The items list in reverse numeric order.
   MsgBox("Deleting the second task item")
   TL.TaskItems.Item(1).Delete()
   MsgBox("Total number of task items: " & TL.TaskItems.Count)
End Sub

See Also

Changing Window Characteristics | Creating and Controlling Environment Windows | Creating Add-Ins and Wizards | Creating an Add-In | Creating a Wizard | Automation and Extensibility Reference | Automation Object Model Chart