How to shift all the tasks to a new "project start" date?
If you parse through all the activities in the gantt and shift the start time, the performance will be poor and get worse as the number of tasks and dependencies grow in your project.
Instead unbind your source list from the gantt, adjust the start times and then rebind the source list to the gantt as follows:
private void moveTasks_Click(object sender, RoutedEventArgs e)
{
// This is where the user specified the new date to shift all the tasks to.
DateTime dt = Convert.ToDateTime(datePicker1.SelectedDate);
// Get a reference to the gantt' bound list.
ObservableCollection<YourTaskObjectType> myObjs = (ObservableCollection<YourTaskObjectType>)this.ganttControl1.ItemsSource;
// First disconnect the source list from the gantt.
this.ganttControl1.ItemsSource = null;
// Then adjust the start time of the tasks
foreach (YourTaskObjectType t in myObjs)
{
// The property could be called PredecessorIndices or something else in your type. This if check is in fact optional, you could instead simply set the StartTime on all the tasks.
if (string.IsNullOrEmpty(t.PredecessorIndices))
t.StartTime = dt;
// This is necessary because only then the dependant tasks will be moved back (in case the Project Start date is being moved back).
t.PreferredStartTime = dt;
}
// The ProjectStartDate is used when the individual tasks do not have a PreferredStartTime set. So, this is optional in this code sample.
this.ganttControl1.ProjectStartDate = dt;
// Rebind the source list with the gantt.
this.ganttControl1.ItemsSource = myObjs;
}
}
� RadiantQ 2009 - 2019. All Rights Reserved.