This project has moved and is read-only. For the latest updates, please go here.

Task Redraw Issue

Nov 15, 2014 at 1:02 AM
Edited Nov 15, 2014 at 1:06 AM
In the attempt of incorporating the control onto my software, I encounter a problem where I am not sure what might be the issue.

At the start of the software, I initialize the ProjectManager to the Chart and then add each Task individually to the ProjectManager and call Invalidate() and Update() on the Chart object every time Task is added, modified, or deleted. I was able to see the changes on the Chart control, but the duration of the Task is not correct. (It has duration of only 1 day.) Only when I attempt to drag the task did the task extends to the right length. I know something is not being updated, but I am not sure what it is.

P.S. Thanks for sharing the source code of the control. It is exactly what I needed.
Nov 15, 2014 at 2:46 AM
Hi Ice_Drake,

Thanks for using the control.

Can you kindly provide the minimum source code to reproduce this bug so that I can take a look?
If it's not a bug, I suspect it has to do with the way the control handles relationships being sometimes different from what some people expect.
Nov 15, 2014 at 5:40 AM
Edited Nov 15, 2014 at 5:49 AM
Hmm...that will be difficult to provide the full code since the way the control and its required elements are incorporated in my software is quite complicated, but I will try my best to simplify the code as much as possible.

GanttChartPanel.cs
public class GanttChartPanel : Form
{
      ...
      private Chart chart;
      ...
      private void InitializeComponent()
      {
            this.chart = new Chart();
            ...
            this.chart.Dock = System.Windows.Forms.DockStyle.Fill;
            this.chart.FullDateStringFormat = null;
            this.chart.Location = new System.Drawing.Point(0, 0);
            this.chart.Margin = new System.Windows.Forms.Padding(0);
            this.chart.Name = "chart";
            this.chart.Size = new System.Drawing.Size(458, 300);
            this.chart.TabIndex = 1;
            ...
      }

      public GanttChartPanel(GoalPlanner goalPlanner)
      {
            InitializeComponent();
            chart.Init(goalPlanner.ProjectManager);
            goalPlanner.GoalModify += new EventHandler(updateChart);
      }
      ...
      private void updateChart(object sender, EventArgs e)
      {
            chart.Invalidate();
            chart.Update();
      }
}
GoalPlanner.cs
public class GoalPlanner
{
      public ProjectManager ProjectManager { get; private set; }
      public event EventHandler GoalModify;
      ...
      public GoalPlanner()
      {
            ...
            ProjectManager = new ProjectManager();
      }
      ...
      public bool createLGoal(...)
      {
            LGoal newGoal = new LGoal();
            ...
            ProjectManager.Add(newGoal);
            ...
            if (GoalModify != null)
                  GoalModify(newGoal, null);
            ...
      }
}
Goal.cs
public class Goal : Task
{
      ...
}
LGoal.cs
public class LGoal : Goal
{
      ...
      public DateTime StartDate
      {
            get
            {
                  return DateTime.Today.AddDays(Start);
            }
            set
            {
                  TimeSpan duration = value - DateTime.Today;
                  Start = duration.Days;
            }
      }

      public DateTime DueDate
      {
            ...
      }
}
LGoalForm.cs
public class LGoalForm : Form
{
      public static GoalPlanner GoalController { private get; set; }
      ...
      private void saveButton_Click(object sender, EventArgs e)
      {
            ...
            GoalController.createLGoal(...);
            ...
      }
}
I ran debugger and found that the value of Start to be 0 and the value of End to be 30 before the task is added to the project manager; yet, the task is drawn to start on the current date and end on tomorrow rather than a month later. After the drag, it looks correct.