System.ArgumentOutOfRangeException on Refresh() FlexGrid (8.0.20251.721)

Posted by: santer.p75 on 3 November 2025, 2:44 pm EST

  • Posted 3 November 2025, 2:44 pm EST

    in the grdFlexGrid.RowColChange event i call grdFlexGrid.Refresh()

    I got this error

    System.ArgumentOutOfRangeException: “Index was out of range. Must be non-negative and less than the size of the collection. (Parameter ‘index’)”

    But only sometimes…

    I switched to the .Net 8 from Frameworke 4.8

    The same code in 4.8 Works fine…

  • Posted 4 November 2025, 7:57 am EST

    Hi,

    Unfortunately, we could not reproduce the issue you mentioned. We tested calling the Refresh method within the RowColChange event of the C1FlexGrid and did not observe any exceptions. Please refer to the attached sample project for reference.

    With the limited information currently available, it is difficult for us to determine the root cause of the issue. We also haven’t received any recent reports of similar behavior in the latest version. Therefore, we request you to share a small sample project, or update the attached one, to reproduce the issue you are facing, so we can investigate further and assist you more effectively.

    Additionally, if the issue occurs only after following specific steps or happens inconsistently, please share a short video demonstrating the behavior. This will help us identify any patterns and understand the scenario better.

    Furthermore, it would be helpful if you could share the complete StackTrace of the issue rather than just the exception type. This will allow us to analyze the call sequence and potentially reproduce the problem by backtracking through the method stack.

    Attachment: FlexGridErrorOnRefresh.zip

    Best Regards,

    Kartik

  • Posted 5 November 2025, 11:10 am EST

    System.ArgumentOutOfRangeException

    HResult=0x80131502

    Nachricht = Index was out of range. Must be non-negative and less than the size of the collection. (Parameter ‘index’)

    Quelle = C1.Win.FlexGrid.8

    Stapelüberwachung:

    bei C1.Win.FlexGrid.C1FlexGridBase.dj(Point a)

    bei C1.Win.FlexGrid.C1FlexGridBase.di()

    bei C1.Win.FlexGrid.C1FlexGridBase.get_TopRow()

    bei C1.Win.FlexGrid.C1FlexGridBase.dm(PaintEventArgs a, DrawColorMode b)

    bei C1.Win.FlexGrid.C1FlexGridBase.OnPaint(PaintEventArgs e)

    bei System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)

    bei System.Windows.Forms.Control.WmPaint(Message& m)

    bei System.Windows.Forms.Control.WndProc(Message& m)

    bei C1.Win.FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)

    bei C1.Win.FlexGrid.C1FlexGridBase.WndProc(Message& m)

    bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

    bei System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

  • Posted 5 November 2025, 3:53 pm EST

    I found now the point where the error is triggerd…

    when i set grd.Redraw = False add rows and the set grd.Redraw = true then the error appears.

    grd.Redraw = true raise the event RowColChange!

    But i cant reproduce in a new emtpy project…

    I use the grid with Footers Footers

    Video:

    https://drive.google.com/file/d/1gwMi_2ztnJiES2rDqegAiDohlEg04F40/view?usp=drive_link

  • Posted 6 November 2025, 4:50 am EST

    Hi,

    Thank you for sharing the StackTrace and the video.

    Unfortunately, we could not view the video from the provided drive link, as it is not publicly accessible. Could you please share a public link so we can view it and check if there are any specific steps that trigger the error?

    Furthermore, we updated our sample project to test the Redraw and AddRows scenario you mentioned, but unfortunately, we could not reproduce the issue. Therefore, please provide a stripped-down project that reproduces the problem you are facing. If the issue cannot be reproduced in a simplified sample, please still share a sample that demonstrates your implementation similar to the main project.

    This will help us share all relevant details with the development team and determine if they can provide additional insights into the error.

    Best Regards,

    Kartik

  • Posted 6 November 2025, 1:21 pm EST

  • Posted 7 November 2025, 3:09 am EST

    Hi,

    Thank you for sharing the video that shows the error. However, we could not clearly understand your code implementation from the video. We could see that you are calling the Refresh method in RowColChange, and also that you have handled the OwnerDrawCell event, which might throw runtime errors if not implemented correctly.

    But, the above information is not enough to track down the issue, as it may also be specific to your implementation. We request you to provide a stripped-down version of your project or a specific module that reproduces the issue you are facing. If you think any information is confidential, you can create a new support case on our private support portal and share the project there.

    In case the project cannot be stripped down, we request you to create a sample project with some sample data similar to your main project, and a similar code implementation/process you use in your main project to trigger the error. Without seeing your code, it would be very difficult for us to investigate further on this.

    Best Regards,

    Kartik

  • Posted 7 November 2025, 4:29 am EST

    Hi,

    to extract a sample project is difficul, the form has 12.000 lines of code…

    When e remove the refresh from the RowColChange event the error does not appear.

    when i set the grid from DrawModeEnum.OwnerDraw to DrawModeEnum.Normal the error persists

    The reason why we do owner draw is becaus flexgrid has no selection mode where the background color of selected cell remains, seleced cell should me transparent. we work a lot with colors and styles…

  • Posted 7 November 2025, 5:08 am EST

    HI, after days of checking the code i found wich line the error makes appear

    It is grd.Rows.Count = 2. When i set to 3 or higher the error disapears.

    But i dont wont empty rows, on load of the rows i wanna start with the 2 rows, on is the caption row and one is the footer row.

    When i set it to 3 then there is a row at the start of the table that we dont need

    Here is a short verion of my code: Cursor = Cursors.WaitCursor

    grd.Redraw = False

    ** grd.Rows.Count = 2****

    Dim drDaten As DataTableReader

    grd.Cols.Count = grd.Cols(“Schlussel”).Index + 1

    AddColsToGrid(grd, False, True, False, “#,##0.00”, True, grd.Cols.Count, “B_”)

    grd.Cols(“Schlussel”).DataMap = GetSchlussel(False)

    drDaten = ReadSQL(“SELECT * FROM Table WHERE Betrieb ='” & sBetrieb & “’ AND Periode =” & nPeriod & " AND Jahr=" & nJahr & " ORDER BY OrderRow")

    While drDaten.Read

    grd.AddItem(“”)

    grd(grd.Rows.Count - 2, “Row”) = grd.Rows.Count - 3

    grd(grd.Rows.Count - 2, “Code”) = drDaten!Code

    CalRow(grd(grd.Rows.Count - 2, “Row”) + 1, grd)

    myKORE.GetSchlüssel(“Keys”, grd.Rows.Count - 2, grd, grd(grd.Rows.Count - 2, “Schlussel”))

    End While

    drDaten.Close()

    bLoad = False

    grd.Redraw = True

    SaveGridSum()

    Cursor = Cursors.Default

  • Posted 10 November 2025, 10:10 am EST

    Hi,

    Apologies for the delayed response.

    Although we could not reproduce the issue you mentioned, we have shared all the details and our observations with the development team to get their insights. We will update you as soon as we receive any information from them.

    [Internal Tracking ID: C1WIN-34704]

    Best Regards,

    Kartik

  • Posted 13 November 2025, 5:15 am EST

    Hi,

    The development team is investigating the issue and mentioned that this exception usually occurs when trying to access a non-existent grid row. To debug further, they suggested checking the number of rows before calling grdLeasing.Refresh() in the grdLeasing_RowColChange handler, as shown in the code below:

    var rows = grdLeasing.Rows.Count
    grdLeasing.Refresh()

    Could you please run the code above and share your observations i.e. whether you get a value or an error for the first statement?

    Also, the development team has also asked if your grid contains groups, footers, or detail rows.

    Best Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels