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;
e.Cell.SetStyle(style);
};
I have reproduced this in an example Visual Studio 2019 project which I have uploaded here:
DesktopGridProblemsNoRef.zip (65.2 KB)
Thanks
Andrew