We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting Cell Background Brush

Thread ID:





109176 Jun 2,2013 05:13 PM UTC Jun 14,2013 11:59 AM UTC WPF 7
Tags: SpreadsheetControl(Classic)
Austin Fay
Asked On June 2, 2013 05:13 PM UTC

I'm having trouble setting a given cells background brush and having it behave consistently. 

Right now I'm trying this C#:
spreadsheet.GridProperties.CurrentExcelGridModel[row, column].Background = Brushes.Black;

The issue is it's inconsistent. Sometimes it works initially, but even if it works on a given cell as soon as the cell loses focus or is re-selected the background property reverts to white. What methodology should I be using to permanently change a cell color?

Pannir Selvam S [Syncfusion]
Replied On June 6, 2013 04:55 PM UTC

Hi Austin,


Thanks for using Syncfusion product.


You can set the background color of the cell in Spreadsheet control by setting the Color of the XlsIO range like in the below code snippet.


Code Snippet[C#]:

IRange range = this.spreadSheetControl.ExcelProperties.WorkBook.ActiveSheet[3,3,5,5];

var clr = Colors.Blue;

range.CellStyle.Color = System.Drawing.Color.FromArgb(clr.A, clr.R, clr.G, clr.B);

this.spreadSheetControl.GridProperties.ActiveSpreadsheetGrid.InvalidateCell(GridRangeInfo.Cells(3, 3, 5, 5));



We have prepared a sample based on this and you can find the sample from the below location.


Please let us know if you have any other queries.





Austin Fay
Replied On June 7, 2013 04:18 PM UTC

I attempted to reapply the code provided for my purposes of coloring a single cell but received only UI lag and no color change for my troubles.

I also attempted to load the example provided and while I did observe the code I was unable to build due to missing the Windows. Interactivity reference. I'm using Windows 8 with VS 2012.

Here is what I am executing:
IRange range = spreadsheet.ExcelProperties.WorkBook.ActiveSheet[row, column];
var clr = Colors.Blue;
range.CellStyle.Color = System.Drawing.Color.FromArgb(clr.A, clr.R, clr.G, clr.B);
spreadsheet.GridProperties.ActiveSpreadsheetGrid.InvalidateCell(GridRangeInfo.Cell(row, column));

Austin Fay
Replied On June 7, 2013 07:46 PM UTC

After installing the Blend SDK I got the sample solution to build. Still getting the weirdest behavior when trying to execute even the exact same code you posted. If I tie the code to a button click, the colors won't take effect until I preform a scroll  action on the excel control. I am successfully changing the colors though.

Austin Fay
Replied On June 11, 2013 05:16 PM UTC

Still waiting on a means to refresh the grid or force a scroll action so these colors show up on a button click.

Pannir Selvam S [Syncfusion]
Replied On June 12, 2013 04:45 AM UTC

Hi Austin,


Apologize for the delay.


You can achieve your requirement by calling the InvalidateVisual() of grid after apply the background color to the cell like in the below code snippet.


Code Snippet[C#]:

var grid = this.spreadSheetControl.GridProperties.ActiveSpreadsheetGrid;

IRange range = this.spreadSheetControl.ExcelProperties.WorkBook.ActiveSheet[3, 3];

var clr = Colors.Blue;

range.CellStyle.Color = System.Drawing.Color.FromArgb(clr.A, clr.R, clr.G, clr.B);

grid.InvalidateCell(GridRangeInfo.Cell(3, 3));




We have attached a sample based on this and you can find the sample from the below location.


Please let us know if you have any other queries.





Austin Fay
Replied On June 12, 2013 12:37 PM UTC

Thank you,  the InvalidateVisual() method addressed my issues.

Pannir Selvam S [Syncfusion]
Replied On June 14, 2013 11:59 AM UTC

Hi Austin,


Thanks for your update.





This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon