RadiantQ WPF Gantt
How to move parent  task along with child task?
Previous Topic  Next Topic 

By default Summary/parent tasks are not editable, it automatically reflects the earliest child start and end times. 


But, GanttControl provides a way to make the Summary/parent tasks editable by setting the AutoCalculateSummaryTaskTimes to false (set this AFTER setting the ItemsSource property of the GanttControl). This will allow the user to move/resize the Summary bar, but you will then have to listen to the ActivityTimeChanged event, determine how much the parent was moved and move the children by the same amount.


Example:

   public MainPage()

    {

        InitializeComponent();


        this.ganttControl.ItemsSource = this.GetDataSource();


        // Setting the AutoCalculateSummaryTaskTimes to false after setting the item source, this way the parent times change when the child times change, and also the parents are moveable in the client.    

        this.ganttControl.AutoCalculateSummaryTaskTimes = false;


        this.ganttControl.ActivityTimeChanged += new EventHandler<ActivityTimeChangedEventArgs>(ganttControl_ActivityTimeChanged);

        this.ganttControl.SelectionChanged += new SelectionChangedEventHandler(ganttControl_SelectionChanged);      

    }   

    void ganttControl_SelectionChanged(object sender, SelectionChangedEventArgs e)

    {

        if (this.ganttControl.SelectedActivity != null)

            this.CacheActivityTimes(this.ganttControl.SelectedActivity);

    }

    //cache the current times of the summary bar.

    private void CacheActivityTimes(IActivity activity)

    {

        this.taskEffort = activity.Effort;

        this.taskStart = activity.StartTime;

    }

    private DateTime taskStart;

    private TimeSpan taskEffort;

    //This gets called when the summary bar is moved or resized. Here we move the children when the summary is moved. Resizes, we don't forward to the children.

    void ganttControl_ActivityTimeChanged(object sender, ActivityTimeChangedEventArgs e)

    {

        IActivity act = e.Activity;

        IActivityView view = this.ganttControl.ActivityViews[act];

        //Check whether the task is parent or not.

        if (view.IsParent)

        {

            // For Task Move

            if (e.Type == ActivityTimeChangeType.StartTimeChanged)

            {

                TimeSpan diff = e.UserSpecifiedTime - this.taskStart;

                //To update the child's start time.

                this.UpdateChildTasksStart(act, diff);

            }

           

            else

            {

                act.Effort = this.taskEffort;


            }


        }

        this.CacheActivityTimes(act);

    }

    // Parse through the children and move them by the specified time span.

    private void UpdateChildTasksStart(IActivity act, TimeSpan diff)

    {

        using (new DelayUpdates())

        {

            foreach (IActivity childActivity in act.ChildActivities)

            {


                childActivity.StartTime = childActivity.StartTime.Add(diff);


                if (childActivity.ChildActivities.Count != 0)

                {

                    this.UpdateChildTasksStart(childActivity, diff);

                }

            }

        }

    }



� RadiantQ 2009 - 2019. All Rights Reserved.