We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cells.GridDesktop: Index Out of Range Exception in OnPaint after setting cells style using Cell.SetStyle

Opening a specific .xls Excel file in .Net Cells GridDesktop with an event on CellClick to change the cell style, if the user clicks all the cells in the first column top to bottom then clicks bottom to top this exception is thrown when the grid tries to re-paint, and subsequent calls to GetStyle fail.

System.IndexOutOfRangeException: Index was outside the bounds of the array.
at ​ . ​ (Int32 )
at . ​ (Int32 )
at . ​ ()
at . ​ ()
at . ​ ()
at Aspose.Cells.GridDesktop.Style.( , Worksheet )
at Aspose.Cells.GridDesktop.GridCell.get_Style()
at Aspose.Cells.GridDesktop.Worksheet. (Int32 , Int32 )
at Aspose.Cells.GridDesktop.GridDesktop.(Int32 , Int32 , Int32 , Int32 , Int32 , Int32 , Int32 , Int32& )
at Aspose.Cells.GridDesktop.GridDesktop.OnPaint(PaintEventArgs e)
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.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

        this.gridDesktop.CellClick += (s, e) =>
            Style style = e.Cell.GetStyle();
            style.ForegroundColor = Color.Orange;
            style.Pattern = GridBackgroundType.Solid;

I have reproduced this in an example Visual Studio 2019 project which I have uploaded here:
DesktopGridProblemsNoRef.zip (65.2 KB)


I had to remove the two Aspose.Cells.Desktop.dll instances from the zip as this bumped it up over the 5MB upload limit.


Please notice, I am able to reproduce the issue as you mentioned by using your sample project with your template file. I found an exception “System.IndexOutOfRangeException” OnPaint after setting cells style using Cell.SetStyle. I have logged a ticket with an id “CELLSNET-48956” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

Please try this fix
Aspose.Cells.GridDesktop.21.8.4.zip (6.7 MB)

That works great, thanks.
Do you have any idea when this will be in the main release and available to download?


Good to know that your issue is sorted out by the new fix. You may use the fix for the time being and wait for our next official release (Aspose.Cells for .NET v21.9) which will be released around mid of September 2021. You will also be notified once the release is published

The issues you have found earlier (filed as CELLSNET-48956) have been fixed in this update. This message was posted using Bugs notification tool by simon.zhao