0
votes

In a test app I was building I came across this error when trying to draw the chart. I have some pseudo-randomly generated data that crashes my test app when trying to draw the Gantt chart...

System.ArgumentOutOfRangeException was unhandled HResult=-2146233086 Message=Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index ParamName=index Source=mscorlib StackTrace: at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at Steema.TeeChart.Styles.Gantt.CopyNextTasks() at Steema.TeeChart.Styles.Gantt.Draw() at Steema.TeeChart.Styles.Series.DrawSeries() at Steema.TeeChart.Chart.DoDraw(Graphics3D g, Int32 First, Int32 Last, Int32 Inc) at Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g) at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools) at Steema.TeeChart.Chart.InternalDraw(Graphics g) at Steema.TeeChart.TChart.Draw(Graphics g) at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:

It appears to be way down in the TeeChart Gantt chart drawing logic.

My project is here: https://www.dropbox.com/sh/haqspd4ux41n2uf/AADkj2H5GLd09oJTW-HrAVr3a?dl=0

if anyone wants to reproduce it.

This test code did used to execute correctly with old 2.0.2670.26520 version of TeeChart.

Seems like my error might be related to the one described here: Exception and endlessly growing designer generated code in InitializeComponent when using Steema TeeChart for .NET 2013 4.1.2013.05280 - What to do?

Any ideas or suggestions on getting around it would be much appreciated.

1

1 Answers

0
votes

This is an error in your code which can be reproduced with this simple code snippet:

  Steema.TeeChart.Styles.Gantt series = new Steema.TeeChart.Styles.Gantt(tChart1.Chart);

  tChart1.Aspect.View3D = false;

  for (int i = 0; i < 10; i++)
  {
    series.Add(DateTime.Now.AddDays(i), DateTime.Now.AddDays(i+5), i, "task " + i.ToString());
    series.NextTasks[series.Count - 1] = series.Count;
  }

When the loop reaches its last iteration (i = 9), NextTasks[9] is being set to 10, an index that doesn't exist (series ranges from 0 to 9) and which causes the index out of range error you get. The solution is making sure that index is never assigned, for example:

  const int max = 10;
  for (int i = 0; i < max; i++)
  {
    series.Add(DateTime.Now.AddDays(i), DateTime.Now.AddDays(i+5), i, "task " + i.ToString());
    series.NextTasks[series.Count - 1] = (i < max - 1) ? series.Count : -1;
  }

The same in your code would be something like this:

      crewSeries.NextTasks[crewSeries.Count - 1] = (crewSeries.Count == crewDataView.Count - 1) ? -1 : crewSeries.Count;