| 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.
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.Start = New DateTime(2012, 6, 25)
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.Start = new DateTime(2012, 6, 25);
t.Duration = 3;
}
}
|
|