How to: Control the Task List

Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions. For more information about upgrading, see FAQ: Converting Add-ins to VSPackage Extensions.

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


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 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 Customizing Development Settings in Visual Studio.

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.

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.

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: 
    System.Windows.Forms.MessageBox.Show("Total number of task items: 

    // Remove the second task item. The items list in reverse numeric 
    // order.
    System.Windows.Forms.MessageBox.Show("Deleting the second task 
    System.Windows.Forms.MessageBox.Show("Total number of task items: