Share via


How to: Control the Task List

The Task List and its contents can be controlled by using automation. It is represented in the Visual Studio automation model by the following objects and collection.

Object Name

Description

TaskList object

Represents the Task List.

TaskItems collection

Represents all 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.

By 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 events.)

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

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Example

The following Add-in example demonstrates how to reference and use the various members of the Task List automation model. This example adds new tasks to the Task List, lists the number of tasks, and then deletes one task. Before running the following example, select Task List from the View menu. The tasks appear in the Addin-ins and Macros category.

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)
    ' Pass the applicationObject member variable to the code example.
    TaskListExample(_applicationObject)
End Sub

Sub TaskListExample(ByVal dte As DTE2)
    Dim tl As TaskList = dte.ToolWindows.TaskList
    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(2).Delete()
    MsgBox("Total number of task items: " & tl.TaskItems.Count)
End Sub
using System.Windows.Forms;
public void OnConnection(object application, ext_ConnectMode   
connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    TaskListExample(_applicationObject);
}

public void TaskListExample(DTE2 dte)
{
    TaskList tl = (TaskList)dte.ToolWindows.TaskList;
    TaskItem tlItem;
    
    // Add a couple of tasks to the Task List.
    tlItem = tl.TaskItems.Add(" ", " ", "Test task 1.",  
      vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser, 
      true, "", 10, true, true);
    tlItem = tl.TaskItems.Add(" ", " ", "Test task 2.", 
      vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment, 
      true, "", 20, true,true);

    // List the total number of task list items after adding the new 
    // task items.
    System.Windows.Forms.MessageBox.Show("Task Item 1 description: 
      "+tl.TaskItems.Item(2).Description);
    System.Windows.Forms.MessageBox.Show("Total number of task items: 
      "+tl.TaskItems.Count);

    // Remove the second task item. The items list in reverse numeric 
    // order.
    System.Windows.Forms.MessageBox.Show("Deleting the second task 
      item");
    tl.TaskItems.Item(2).Delete();
    System.Windows.Forms.MessageBox.Show("Total number of task items: 
      "+tl.TaskItems.Count);
}

See Also

Tasks

How to: Change Window Characteristics

How to: Create an Add-In

Walkthrough: Creating a Wizard

Reference

Task List (Visual Studio)

Concepts

Automation Object Model Chart

Other Resources

Creating and Controlling Environment Windows

Creating Add-ins and Wizards

Automation and Extensibility Reference