2015-10-19 191 views
0

在我正在構建的測試應用程序中,當試圖繪製圖表時遇到了此錯誤。我試圖繪製甘特圖時崩潰我的測試應用中的一些僞隨機生成的數據...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?

圍繞它得到任何意見或建議,將不勝感激。

回答

0

這是在代碼中的錯誤,可以用這個簡單的代碼段被再現:

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 <= crewDataView.Count - 1)? crewSeries.Count:-1;' –

+0

是的,你說得對。我更正了我的答案:crewSeries.NextTasks [crewSeries.Count - 1] =(crewSeries.Count == crewDataView.Count - 1)? -1:crewSeries.Count ;.重點不在於系列中的最後一項任務應指向-1,而應指向0到crewSeries.Count - 1範圍內的現有索引。 –