图甘特图系统.参数outofrangeexception未处理"错误

本文关键字:quot 错误 未处理 outofrangeexception 系统 参数 | 更新日期: 2023-09-27 18:18:34

在我正在构建的一个测试应用程序中,我在尝试绘制图表时遇到了这个错误。我有一些伪随机生成的数据,在尝试绘制甘特图时崩溃了我的测试应用程序…

系统。ArgumentOutOfRangeException未处理HResult=-2146233086消息=索引超出范围。必须非负且小于集合的大小。参数名称:index ParamName=indexSource=mscorlib StackTrace: atSystem.ThrowHelper.ThrowArgumentOutOfRangeException (ExceptionArgument参数,例外资源,资源)Steema.TeeChart.Styles.Gantt.CopyNextTasks ()Steema.TeeChart.Styles.Gantt.Draw ()Steema.TeeChart.Styles.Series.DrawSeries ()Steema.TeeChart.Chart。DoDraw(Graphics3D g, Int32 First, Int32 Last,Int32 Inc)在Steema.TeeChart.Chart。DrawAllSeries(Graphics3DSteema.TeeChart.Chart。内部绘制(图形,布尔noTools)在Steema.TeeChart.Chart。内部绘制(图形)在Steema.TeeChart.TChart。绘图(图形)Steema.TeeChart.TChart。OnPaint(PaintEventArgs)System.Windows.Forms.Control。PaintWithErrorHandling (PaintEventArgs e,在system . windows . forms . control . wmppaint (Message&米)System.Windows.Forms.Control.WndProc (Message&米)System.Windows.Forms.Control.ControlNativeWindow.OnMessage (Message&米)在System.Windows.Forms.Control.ControlNativeWindow.WndProc (Message&m)在system . windows . forms . nativewindows . debuggablecallback (IntPtrhWnd, Int32 msg, IntPtr wparam, IntPtr lparam) InnerException:

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

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

如果有人想复制它

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

似乎我的错误可能与下面描述的错误有关:当使用Steema TeeChart for .NET 2013时,在InitializeComponent中生成的异常和不断增长的设计器生成的代码4.1.2013.05280 -怎么办?

图甘特图系统.参数outofrangeexception未处理"错误

如果您有什么想法或建议,我将不胜感激。

这是你代码中的一个错误,可以用下面这个简单的代码片段来重现:

  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;