C1FlexGrid 'Failed to compare two elements in the array' error

Posted by: tom.galczynski on 9 October 2025, 3:17 pm EST

  • Posted 9 October 2025, 3:17 pm EST

    Hello support! We have recently had a couple of users report an issue that we cannot reproduce but they can and we were hoping you could provide a little guidance as to possible causes? It involves C1.Win.C1FlexGrid version 4.8.20241.664. IN the form we are rebuilding the grid each time the user clicks on a row of a treeview control. It seems they can do this a couple of times but at some point they get this error:

    System.InvalidOperationException: Failed to compare two elements in the array. —> System.ArgumentException: Object must be of type Int32.

    at System.Int32.CompareTo(Object value)

    at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)

    — End of inner exception stack trace —

    at System.Array.BinarySearch(Array array, Int32 index, Int32 length, Object value, IComparer comparer)

    at System.Collections.SortedList.IndexOfKey(Object key)

    at System.Collections.SortedList.Contains(Object key)

    at ax.w(Int32 a, Int32 b)

    at ax.cd(Int32 a, Int32 b, Image& c, CheckEnum& d)

    at C1.Win.C1FlexGrid.C1FlexGridBase.DrawCell(PaintEventArgs e, Int32 row, Int32 col, DrawColorMode colorMode)

    at C1.Win.C1FlexGrid.C1FlexGrid.DrawCell(PaintEventArgs e, Int32 row, Int32 col, DrawColorMode colorMode)

    at C1.Win.C1FlexGrid.C1FlexGrid.DrawRow(PaintEventArgs e, Int32 row, DrawColorMode colorMode)

    at C1.Win.C1FlexGrid.C1FlexGridBase.dj(PaintEventArgs a, DrawColorMode b)

    at C1.Win.C1FlexGrid.C1FlexGridBase.OnPaint(PaintEventArgs e)

    at AdvancedSoftwareDesigns.Windows.Forms.FlexGrid._onPaint(PaintEventArgs e) in C:\VS2015\ProductVision 5.2\Build 5.4.1003.11\ASD Libraries\AdvancedSoftwareDesigns.Windows.Forms\Windows\Forms\FlexGrid.vb:line 1150

    at AdvancedSoftwareDesigns.Windows.Forms.FlexGrid.OnPaint(PaintEventArgs e) in C:\VS2015\ProductVision 5.2\Build 5.4.1003.11\ASD Libraries\AdvancedSoftwareDesigns.Windows.Forms\Windows\Forms\FlexGrid.vb:line 1176

    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 C1.Win.C1FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)

    at C1.Win.C1FlexGrid.C1FlexGridBase.WndProc(Message& m)

    at AdvancedSoftwareDesigns.Windows.Forms.FlexGrid.WndProc(Message& m) in C:\VS2015\ProductVision 5.2\Build 5.4.1003.11\ASD Libraries\AdvancedSoftwareDesigns.Windows.Forms\Windows\Forms\FlexGrid.vb:line 433

    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    The grid has about a dozen columns, mostly boolean and like I say it paints fine a couple of times for them but then throws this error when they next click a row in the treeview and we rebuild the grid. We cannot reproduce it in a debugger. One user has a laptop which throws the error and cannot reproduce on a desktop so maybe hardware related???

    Any guidance would be appreciated. Thanks!

  • Posted 10 October 2025, 7:19 am EST

    Hi Tom,

    We created a TreeGrid sample with around a dozen Boolean columns and added a grid refresh on row selection change. However, we couldn’t reproduce the error on our end. We’ve attached the sample application for your reference: TreeGridDemo.zip.

    In the past, one of our customers faced a similar issue, which was caused by a DBNull value in the data. That problem was fixed in version 4.5.20213.533, and it was specific to their machine setup.

    Since you’re using version 4.8.20241.664, we recommend testing the issue with the latest build 4.8.20251.721 on the laptop where the error occurs. If the issue still happens, please share the following details:

    • Machine specifications and OS version
    • Any settings that might differ from other machines where it works fine
    • A minimal sample that reproduces the issue along with the exact steps to trigger it

    We highly appreciate your cooperation.

    Thanks & regards,

    Aastha

  • Posted 13 October 2025, 10:36 am EST

    My apologies. I was mistaken when I said the columns were “mostly boolean”. In fact they are set up to use an ImageMap:

    With Me.FlexGridDetails.Cols.Add

    .Name = “fmincluded”

    .Caption = " "c

    .DataType = Nothing

    .ImageAndText = False

    .AllowEditing = False 'The editing will be handled in the click event

    .UserData = SecurityAssign._checkboxColumn 'Designate this as a ‘checkbox’ column.

                        'Assign the images of the checkboxes.
                        .ImageMap = Me._colImages
                        .ImageAndText = False
                        .ImageAlign = C1.Win.C1FlexGrid.ImageAlignEnum.CenterCenter
                    End With
    

    We then load the data like this: Me.FlexGridDetails(row.Index, col.Index) = 5I

    Each cell has a value between 0 and 5 and there are 6 images in Me._colImages which are checkboxes, blank, checked, grayed out etc. We do plan on going to the latest version in our next build so will re-test then. If you see anything in the above setup of the column that could be a factor, please let me know. Thanks!

  • Posted 14 October 2025, 7:17 am EST - Updated 14 October 2025, 7:22 am EST

    Hi Tom,

    Thanks for sharing the additional details. We would really appreciate you testing the issue with the latest version.

    In the meantime, we’ve updated our sample app to use ImageMap as described. Please check the attached file: TreeGridDemo_Mod.zip.

    Unfortunately, we could not reproduce the issue on our side. You can see it working in the attached GIF:

    Could you please update the sample application with your setup so we can better understand your scenario? Let us know if you notice any details that help replicate the issue.

    Thanks & regards,

    Aastha

Need extra support?

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

Learn More

Forum Channels