Results 1 to 7 of 7

Thread: datagrid, arraylist System.IndexOutOfRangeException error

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2005
    Posts
    1

    datagrid, arraylist System.IndexOutOfRangeException error

    I am using VB.Net to create a datagrid (OrderGrid) and I am binding it to an arraylist(OrderArrayList). The arraylist is composed of objects of a user defined class (OrderClass).

    The datagrid is being used to display all the properties of these objects contained in the arraylist.

    The datagrid is able to handle Additions, Modifications, and Removals of objects from the arraylist. Any change done is properly displayed on the datagrid in normal situation.

    The problem happens when the speed of Additions, Modifications, and particularly Removals on the objects contained in the arraylist increase.

    As that happens I get the following error:

    System.IndexOutOfRangeException: No value at index 5.
    at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
    at System.Windows.Forms.DataGridRow.PaintHeader(Graphics g, Rectangle visualBounds, Boolean alignToRight, Boolean rowIsDirty)
    at System.Windows.Forms.DataGridRelationshipRow.PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean isDirty)
    at System.Windows.Forms.DataGridRelationshipRow.PaintHeader(Graphics g, Rectangle bounds, Boolean alignToRight, Boolean isDirty)
    at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle& boundingRect)
    at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
    at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
    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.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    at System.Windows.Forms.SafeNativeMethods.UpdateWindow(HandleRef hWnd)
    at System.Windows.Forms.Control.Update()
    at System.Windows.Forms.Control.Refresh()
    at MktDesignPattern.Display.OrderGrid() in C:\Display.vb:line 414

    At line 414 I am calling the OrderGrid.Refresh() after I am done with removal of an object in the arraylist.

    I would appreciate if anyone can help me in dealing with this error.

    I have read few articles on the MSDN about databinding and the behaviour of datagrids, and have extensively searched ab't this problem on userforums and have tried to implement the suggestions provided there to the best of my knowledge. A lot of people seem to have similar problem but this problem is unique because I get it only when the change/add/remove happens on the objects contained in the arraylist happens at a higher speed.

    I was using DataSet and DataTables intially and was getting the unhandledexception NullObjectReferenceException, when I switched to ArrayList I started getting System.IndexOutOfRangeException.

    I am using synchronized arraylist and I am also making sure that there is no concurrent access of the objects in the arraylist.

    I am assuming that this error is happening during the course of datagrid trying to push whatever additions/changes/removals in the arraylist onto the screen. I remove the databinding before I do any changes, make the OrderGrid.datasource = Nothing, refresh the grid make the change to the arraylist and rebind and refresh the data but even that does not seem to take care of this exception.

    I would be glad to give any other information if someone can help me.

    -Sumit

  2. #2
    Junior Member
    Join Date
    Sep 2005
    Posts
    18

    Re: datagrid, arraylist System.IndexOutOfRangeException error

    Why dont you program with command builder?
    I think, using code is better than tool because when you upadte through table.upadate
    there are alot of errors which are difficult to catch.

  3. #3
    New Member
    Join Date
    Dec 2021
    Posts
    2

    Re: datagrid, arraylist System.IndexOutOfRangeException error

    This is quite old, but were you able to solve this? Im having an identical exception here and no way to figure out from where it is coming.

    Thanks

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,504

    Re: datagrid, arraylist System.IndexOutOfRangeException error

    Quote Originally Posted by Leonardo_ View Post
    This is quite old, but were you able to solve this? Im having an identical exception here and no way to figure out from where it is coming.

    Thanks
    Indices are zero to count - 1. Any number outside that range gives an IndexOutOfRangeException

  5. #5
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    4,832

    Re: datagrid, arraylist System.IndexOutOfRangeException error

    Quote Originally Posted by Leonardo_ View Post
    This is quite old, but were you able to solve this? Im having an identical exception here and no way to figure out from where it is coming.

    Thanks
    If .Paul's answer doesn't help you solve your problem then you really should start a new thread and not dig up a thread this old. Post the relevant code, indicate which line is causing the error.

    That being said, you should be able put a break point at the line that errors and check the value of any index's. You probably can spot the bad index.

  6. #6
    New Member
    Join Date
    Dec 2021
    Posts
    2

    Re: datagrid, arraylist System.IndexOutOfRangeException error

    The reason I didn't create a new thread is because the exception Im receiving is identical to this old post.

    The difference is that the stack trace starts in DebuggableCallback and it is being very difficult to find the point where the flow is starting (to use breakpoints and debug).

    System.IndexOutOfRangeException: No value at index 0
    at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
    at System.Windows.Forms.DataGridRow.PaintHeader(Graphics g, Rectangle visualBounds, Boolean alignToRight, Boolean rowIsDirty)
    at System.Windows.Forms.DataGridRelationshipRow.PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean isDirty)
    at System.Windows.Forms.DataGridRelationshipRow.PaintHeader(Graphics g, Rectangle bounds, Boolean alignToRight, Boolean isDirty)
    at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle& boundingRect)
    at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
    at System.Windows.Forms.DataGrid.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)

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,893

    Re: datagrid, arraylist System.IndexOutOfRangeException error

    Quote Originally Posted by Leonardo_ View Post
    The reason I didn't create a new thread is because the exception Im receiving is identical to this old post.

    The difference is that the stack trace starts in DebuggableCallback and it is being very difficult to find the point where the flow is starting (to use breakpoints and debug).

    System.IndexOutOfRangeException: No value at index 0
    at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
    at System.Windows.Forms.DataGridRow.PaintHeader(Graphics g, Rectangle visualBounds, Boolean alignToRight, Boolean rowIsDirty)
    at System.Windows.Forms.DataGridRelationshipRow.PaintHeaderInside(Graphics g, Rectangle bounds, Brush backBr, Boolean alignToRight, Boolean isDirty)
    at System.Windows.Forms.DataGridRelationshipRow.PaintHeader(Graphics g, Rectangle bounds, Boolean alignToRight, Boolean isDirty)
    at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle& boundingRect)
    at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle gridBounds)
    at System.Windows.Forms.DataGrid.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)
    Start a new thread and provide all the relevant details, including exactly what the user and/or the application is doing when the exception is thrown.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width