ComponentOne GanttView for WinForms
Inserting a Task
GanttView for WinForms Task-Based Help > Inserting a Task

This topic illustrates how to insert a task at run time or in code. At run time, you can insert a task between existing tasks by selecting the row below where you want a new task to appear or you can use the index to programmatically specify the position of the new task.

Insert a task at run time

  1. In the Task Name field of the grid, type a task name at the end of the task list.
    Notice as you type the C1GanttView toolbar items will become disabled.
     
  2. Press ENTER and the New Task item will appear in the grid. The C1GanttView toolbar items will become enabled.

Insert a task in code

To programmatically insert a task, complete the following:

To write code in Visual Basic

Visual Basic
Copy Code
Private Sub btnInsertTask_Click(sender As Object, e As EventArgs)
   Dim tasks As TaskCollection = ganttView.Tasks
   Dim index As Integer = tasks.IndexOf("Task 2")
   If index >= 0 Then
      ' create a new task
      Dim t As New Task()
      tasks.Insert(index, t)
      t.Mode = TaskMode.Automatic
      t.Name = "New Task"
      t.Duration = 3
   End If
End Sub

To write code in C#

C#
Copy Code
private void btnInsertTask_Click(object sender, EventArgs e)
    {
        TaskCollection tasks = ganttView.Tasks;
        int index = tasks.IndexOf("Task 2");
        if (index >= 0)
        {
            // create a new task
            Task t = new Task();
            tasks.Insert(index, t);
            t.Mode = TaskMode.Automatic;
            t.Name = "New Task";
            t.Duration = 3;
        }
    }
See Also