Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Index was out of range. Must be non-negative and less than the size of the collection.

I'm getting an exception in my application. It occurs when drawing resumes after removing all annotations from my ScatterGraph. Any idea what could be causing this and what I can do to fix it?

Here is the exception:

Index was out of range. Must be non-negative and less than the size of the collection.

   at System.Collections.ArrayList.get_Item(Int32 index)
   at NationalInstruments.Restricted.ControlElementCollection.get_Item(Int32 index)
   at NationalInstruments.UI.Internal.cg.a(ComponentDrawArgsInternal A_0)
   at NationalInstruments.UI.Internal.au.b(ComponentDrawArgsInternal A_0)
   at NationalInstruments.UI.Internal.r.b(ComponentDrawArgsInternal A_0)
   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1, Boolean A_2)
   at NationalInstruments.Restricted.ControlElement.DrawChildren(ComponentDrawArgsInternal args, Rectangle clipRectangle)
   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1, Boolean A_2)
   at NationalInstruments.Restricted.ControlElement.a(ComponentDrawArgsInternal A_0, Rectangle A_1)
   at NationalInstruments.Restricted.ControlElement.Paint(PaintEventArgs e)
   at NationalInstruments.UI.WindowsForms.ControlBase.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   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)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)

Thanks.
0 Kudos
Message 1 of 3
(5,833 Views)
there probably is a read or a write to scatterGraph1.Annotations[i] after you removed them all...
Try just switching them to Visible = false instead of removing them.
0 Kudos
Message 2 of 3
(5,819 Views)
Thanks for the response. Unfortunately I'm in a situation where I need to remove annotations - when the user moves to a different portion of the dataset I need to draw annotations corresponding to that portion, and eventually remove the old annotations as otherwise too much memory could be consumed.

Rather than using the XYRangeAnnotation class, I'm going to try drawing my own annotations by overriding the AfterDrawPlotArea method.
0 Kudos
Message 3 of 3
(5,814 Views)