Changing cell color throws an exception

Posted by: adecmagnus on 8 September 2017, 12:51 pm EST

  • Posted 8 September 2017, 12:51 pm EST

    In my spread, I want to indicate the cells that have been changed with color. Simple task, right?


    Well, the following code, used in the handler for the CellChanged event, throws a "StackOverflowException" in FarPoint.Win.Spread.dll.


    fpSpread1.ActiveSheet.Cells[e.Row, e.Column].BackColor = System.Drawing.Color.LimeGreen;


    I have also tried


    fpSpread1.ActiveSheet.ActiveCell.BackColor = System.Drawing.Color.LimeGreen;


    with the same strange result.


    Can anyone help me out here? Thanks.


    Magnus

  • Replied 8 September 2017, 12:51 pm EST

    Magnus,


    This code, changing the BackColor for a cell, will cause the CellChanged event to refire. This will put your code in an infinite loop and then throw a stack overflow exception. You either need to move the code to a different event, or write code to make sure it does not get called because you are programatically setting the BackColor.

  • Replied 8 September 2017, 12:51 pm EST

    Ok, thanks! I thought CellChanged refered to value only. I'll try to work around it somehow.


     

Need extra support?

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

Learn More

Forum Channels