Share via


TaskItems2.Add Method

Adds a new task item to the TaskList.

Namespace:  EnvDTE80
Assembly:  EnvDTE80 (in EnvDTE80.dll)

Syntax

'Declaration
Function Add ( _
    Category As String, _
    SubCategory As String, _
    Description As String, _
    Priority As vsTaskPriority, _
    Icon As Object, _
    Checkable As Boolean, _
    File As String, _
    Line As Integer, _
    CanUserDelete As Boolean, _
    FlushItem As Boolean _
) As TaskItem
TaskItem Add(
    string Category,
    string SubCategory,
    string Description,
    vsTaskPriority Priority,
    Object Icon,
    bool Checkable,
    string File,
    int Line,
    bool CanUserDelete,
    bool FlushItem
)
TaskItem^ Add(
    [InAttribute] String^ Category, 
    [InAttribute] String^ SubCategory, 
    [InAttribute] String^ Description, 
    [InAttribute] vsTaskPriority Priority, 
    [InAttribute] Object^ Icon, 
    [InAttribute] bool Checkable, 
    [InAttribute] String^ File, 
    [InAttribute] int Line, 
    [InAttribute] bool CanUserDelete, 
    [InAttribute] bool FlushItem
)
abstract Add : 
        Category:string * 
        SubCategory:string * 
        Description:string * 
        Priority:vsTaskPriority * 
        Icon:Object * 
        Checkable:bool * 
        File:string * 
        Line:int * 
        CanUserDelete:bool * 
        FlushItem:bool -> TaskItem
function Add(
    Category : String, 
    SubCategory : String, 
    Description : String, 
    Priority : vsTaskPriority, 
    Icon : Object, 
    Checkable : boolean, 
    File : String, 
    Line : int, 
    CanUserDelete : boolean, 
    FlushItem : boolean
) : TaskItem

Parameters

  • Category
    Type: String

    Required. Represents the category name of the task item.

  • SubCategory
    Type: String

    Required. Represents the subcategory name of the task item.

  • Description
    Type: String

    Required. Describes the task item.

  • Icon
    Type: Object

    Optional. Determines the type of icon that represents the new task item. The setting must be either vsTaskIcon or an IPictureDisp.

  • Checkable
    Type: Boolean

    Optional. Indicates whether or not you want the task item to provide a checkbox that users can check to indicate the task is complete. The default value is false.

  • File
    Type: String

    Optional. Indicates the file or path associated with the new task item. The default value is an empty string (""), and if this is used, IsSettable(vsTaskListColumnFile) returns false. The file name can be a full path, a relative path, or simply a file name. Note that associating a file or path with an item does not necessarily mean that it performs any actions.

  • Line
    Type: Int32

    Optional. Indicates the line in the source code associated with the new task item. The default value is 0, and if this is used, IsSettable(vsTaskListColumnLine) returns false. Note that associating a line number with an item does not necessarily mean that it performs any actions.

  • CanUserDelete
    Type: Boolean

    Optional. Indicates whether a user can delete the new task item by pressing DELETE when the item is selected in the environment. The default value is true.

  • FlushItem
    Type: Boolean

    Optional. Indicates whether a new item is immediately visible in the Task List. When FlushItem is set to true, the Task List is updated immediately after Add is called. When FlushItem is set to false, the Task List is updated later after all updates are made. A false setting is used primarily to enhance performance when you are adding many items at a time to the Task List. The default value is true.

Return Value

Type: EnvDTE.TaskItem
A TaskItem object.

Remarks

When adding bitmaps, the RGB color 0x0000FF00 (green) is transparent. All places in your picture that use this value are transparent and the Task List shows through.

The width and height of bitmaps must be 16 x 16 pixels.

If using IPictureDisp, the PICTYPE argument must be set to either Icon or Bitmap. Settings of Metafiles, Uninitialized, or None do not work correctly.

Examples

This example adds two task items to the task list and displays some of their properties in message boxes. For more information about how to run this example as an add-in, see How to: Compile and Run the Automation Object Model Code Examples.

Imports EnvDTE
Imports EnvDTE80
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)
    TaskItems2Example(_applicationObject)
End Sub
Sub TaskItems2Example(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.
    TLItem = TLItems.Add(" ", " ", "Test task 1.", _
     vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser _
    , True, , 10, , )
     TLItem = TLItems.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: " & TLItems.Item(2).Description)
    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 OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    TaskItems2Example(_applicationObject);
}
public void TaskItems2Example(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.Add("MyTask", "MyTask1", "Test task 1."
, vsTaskPriority.vsTaskPriorityHigh, vsTaskIcon.vsTaskIconUser
, true,null,10,true,true );
    TLItem = TLItems.Add("MyTask", "MyTask1", "Test task 2."
, vsTaskPriority.vsTaskPriorityLow, vsTaskIcon.vsTaskIconComment
, true, null, 20, true, true);
    // 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("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);
}

.NET Framework Security

See Also

Reference

TaskItems2 Interface

EnvDTE80 Namespace