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.

Using QueryCellSyleInfo to change text color

Thread ID:

Created:

Updated:

Platform:

Replies:

58118 Mar 19,2007 11:17 AM Mar 21,2007 02:21 PM ASP.NET Web Forms (Classic) 5
loading
Tags: GridGroupingControl
Administrator [Syncfusion]
Asked On March 19, 2007 11:17 AM

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;

}
}
}

Gokul B [Syncfusion]
Replied On March 19, 2007 09:05 PM

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

Rachael Smith
Replied On March 20, 2007 04:31 AM



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

Rachael Smith
Replied On March 20, 2007 07:41 AM

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

Rachael Smith
Replied On March 20, 2007 07:45 AM

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

Gokul B [Syncfusion]
Replied On March 21, 2007 02:21 PM

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

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.

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.

;