Add / Remove Items

Before proceding with adding/removing items, check Types of Items topic.

Add Items

In order to add new item to RadGanttView, first you have to create an instance of the class Telerik.Windows.Controls.GanttView.GanttTask, set its properties like Start, End, Title etc, and then add it to the TasksSource collection of the control.

var summaryTask = new GanttTask() 
{ 
 Start = new DateTime(2012,2,13), 
 End = new DateTime(2012,2,20), 
 Title = "Iteration 3", 
 Progress = 45 
}; 
 
Tasks.Add(summaryTask); 

In case you need to add a child to a summary task, you should add it to its Children collection:

var task1 = new GanttTask() 
{ 
 Start = new DateTime(2012,2,13), 
 End = new DateTime(2012, 2, 16), 
 Title = "testing" 
}; 
 
var task2 = new GanttTask() 
{ 
 Start = new DateTime(2012, 2, 16), 
 End = new DateTime(2012, 2, 20), 
 Title = "fixing" 
}; 
summaryTask.Children.Add(task1); 
summaryTask.Children.Add(task2); 

Remove Items

In order to remove a task you have to remove it from the TasksSource collection of the control or Children collection of a summary task:

summaryTask.Children.Remove(task1); 
summaryTask.Children.RemoveAt(0); 
 
Tasks.Remove(summaryTask); 

Note that when removing a task, you should also remove programmatically the relations to this item.

See Also

In this article