Export (0) Print
Expand All

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.

NoteNote:

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.

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 Add-ins and Macros category of the Task List.

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);
}

Community Additions

ADD
Show:
© 2014 Microsoft