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. Image for the cookie policy date

Using QueryCellSyleInfo to change text color

Hi,

I am trying to change the color of my cells to red if they contain a negative number. I am using the code below and I have debugged to ensyre that the color is indeed being set to red for negatives. However when my grid is displayed the negative cells have not changed and the font color is still balck. Any ideas what i might be doing wrong?

Thanks.


protected void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{

if ((e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell))
{

if (e.Style.CellValueType == typeof(System.Int32))
{

if ((System.Int32)e.Style.CellValue < 0)

e.Style.TextColor = Color.Red;
e.Style.CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised;

}
}
}

5 Replies

GB Gokul B Syncfusion Team March 20, 2007 01:05 AM UTC

Hi Racheal,

We can able to reproduce the issue as you mentioned. We found that below code snippet is causing this issue.

if (e.Style.CellValueType == typeof(System.Int32))

Since, in your scenario e.Style.CellValueType will always points to String type. So please comment and above line and try the below snippet.

if ((e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell))
{

if (Convert.ToInt32(e.Style.CellValue) < 0)
{
e.Style.TextColor = Color.Red;
e.Style.CellAppearance = Syncfusion.Windows.Forms.Grid.GridCellAppearance.Raised;
}
}

Let us know if it helps.

Thanks for using Syncfusion products.

Regards,
Gokulkumar.B


RS Rachael Smith March 20, 2007 08:31 AM UTC



Hi,

Thanks for your reply. This line

if (e.Style.CellValueType == typeof(System.Int32))<

is not causing me any issues as I have previously set the cell type of my columns to System.Int32. The code snippet itself seems to be running correctly. I have debugged into the code and for my cells with negative numbers, the line

e.Style.TextColor = Color.Red;

is run and from debugging it appears that at that point the Style.TextColor is indeed red. In my mind there must be something which is overulling this change. I have checked that my ajax implementation is not the cause of the table not redering with these changes and I have checked that the style sheets i have applied are not overulling this change. Any ideas what am I missing?

Thanks


RS Rachael Smith March 20, 2007 11:41 AM UTC

Hi,

I have found my problem. In the aspx page under of the GridGroupingControl I had the following line.



The addition of this line means that any changes made to the appearance of AnyRecordFieldCell in the code behind are not rendered. The css is:
.AnyRecordFieldCellStyle
{
background-color: #e1f4fe;
}
Therefore I was not even setting the text color in the css. I don't see why having a css listed should prevent the code behind from changing apperance settings. Can you shed any light on this?

Thanks


RS Rachael Smith March 20, 2007 11:45 AM UTC

Sorry. the line that seems to have disappeared from my previous post was:
AnyRecordFieldCell CssClass="AnyRecordFieldCellStyle">
The post should read:
Hi,

I have found my problem. In the aspx page under of the GridGroupingControl I had the following line



The addition of this line means that any changes made to the appearance of AnyRecordFieldCell in the code behind are not rendered. The css is:

.AnyRecordFieldCellStyle
{
background-color: #e1f4fe;
}

Therefore I was not even setting the text color in the css. I don't see why having a css listed should prevent the code behind from changing apperance settings. Can you shed any light on this?

Thanks


GB Gokul B Syncfusion Team March 21, 2007 06:21 PM UTC

Hi Racheal,

Sorry for the delay in getting back to you.

We couldn't able to reproduce the issue as you mentioned. In the QueryCellStyleInfo event the textcolor of an cell was changing well even if we set the CellValueType as "System.Int32". To ensure this we have attached one sample for your references. If anything we made wrong please correct us.

GridFormatSample

*In our sample, we change the textcolor of an cell as "Red" if CellValue of "pub_id" is less than "0877".

Let us know if our sample helps.

Thanks for your patience.

Regards,
Gokulkumar.B

Loader.
Live Chat Icon For mobile
Up arrow icon