TeeChart甘特图“System.ArgumentOutOfRangeException未处理”错误

问题描述:

在我正在构建的测试应用程序中,当试图绘制图表时遇到了此错误。我试图绘制甘特图时崩溃我的测试应用中的一些伪随机生成的数据...TeeChart甘特图“System.ArgumentOutOfRangeException未处理”错误

System.ArgumentOutOfRangeException了未处理的HResult = -2146233086 消息=索引超出范围。必须是非负数,并且小于集合的大小 。参数名称:索引= PARAMNAME指数 源= mscorlib程序堆栈跟踪:在 System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument 说法,ExceptionResource资源)处 Steema.TeeChart.Styles.Gantt Steema.TeeChart.Styles.Gantt.CopyNextTasks() Steema.TeeChart.Chart.DrawAllSeries(Graphics3D g,Int32 First,Int32 Last, Int32 Inc)。克)在 Steema.TeeChart.Chart.InternalDraw(图形克,布尔noTools)处 Steema.T Steema.TeeChart.Chart.InternalDraw(图形克)在 Steema.TeeChart.TChart.Draw(图形克) eeChart.TChart.OnPaint(PaintEventArgs的PE)在 System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs的E, Int16的层)在System.Windows.Forms.Control.WmPaint(消息& m)上 System.Windows.Forms的.Control.WndProc(消息& m)上 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息&米) 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息& m)上System.Windows .Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)InnerException:

它似乎在TeeChart甘特图绘制逻辑中下降了。

我的项目是在这里:https://www.dropbox.com/sh/haqspd4ux41n2uf/AADkj2H5GLd09oJTW-HrAVr3a?dl=0

如果有人想复制它。

此测试代码确实用于在旧版本的TeeChart 2.0.2670.26520版本中正确执行。

好像我的错误可能与此处描述的: Exception and endlessly growing designer generated code in InitializeComponent when using Steema TeeChart for .NET 2013 4.1.2013.05280 - What to do?

围绕它得到任何意见或建议,将不胜感激。

这是在代码中的错误,可以用这个简单的代码段被再现:

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; 
    } 

当环路达到其最后一次迭代(I = 9),NextTasks [9]被设定到10,一个不存在的索引(系列范围从0到9),并导致索引超出范围错误,你会得到。该解决方案是确保指标从未分配,例如:

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; 
    } 

在你的代码同样会是这样的:

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

感谢您的答复纳西斯。我想我明白我要去哪里错了。每个系列的最后一项任务必须以-1结尾。不过,我不确定你的建议是否完全正确。我想: 'crewSeries.NextTasks [crewSeries.Count - 1] =(crewSeries.Count == crewDataView.Count - 1)? crewSeries.Count:-1;' 应该是: 'crewSeries.NextTasks [crewSeries.Count - 1] =(crewSeries.Count

+0

是的,你说得对。我更正了我的答案:crewSeries.NextTasks [crewSeries.Count - 1] =(crewSeries.Count == crewDataView.Count - 1)? -1:crewSeries.Count ;.重点不在于系列中的最后一项任务应指向-1,而应指向0到crewSeries.Count - 1范围内的现有索引。 –