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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting Cell Background Brush

Thread ID:

Created:

Updated:

Platform:

Replies:

109176 Jun 2,2013 01:13 PM Jun 14,2013 07:59 AM WPF 7
loading
Tags: SpreadsheetControl(Classic)
Austin Fay
Asked On June 2, 2013 01:13 PM

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 12:55 PM

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.

 

Thanks,

Pannir



SpreadsheetDemo_WPF_376d7067.zip

Austin Fay
Replied On June 7, 2013 12:18 PM

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 03:46 PM

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 01:16 PM

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 12:45 AM

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));

grid.InvalidateVisual();

 

 

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.

 

Thanks,

Pannir



SpreadsheetDemo_WPF_4a08a828.zip

Austin Fay
Replied On June 12, 2013 08:37 AM

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

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

Hi Austin,

 

Thanks for your update.

 

Regards,

Pannir


CONFIRMATION

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.

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

;