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

Change Text-Color of a cell depending on a property of the ItemsSource

Thread ID:





99819 Jun 14,2011 10:24 AM UTC Jun 17,2011 01:44 PM UTC WPF 5
Tags: GridControl
Lukas Reusch
Asked On June 14, 2011 10:24 AM UTC


I want to change the text-color of one column of my GridDataControl, if a property in the row-"object" (ItemsSource) is a specific value.

For example:

I bind a list of objects with the following properties to the GridDataControl:
- ID
- Request
- IsImportant

And now I want to set the text-color of the ID to red if the request is important.

Thank you very much,

Manikandan [Syncfusion]
Replied On June 15, 2011 01:41 PM UTC

Hi Peter,

Thanks for using Syncfusion Products.

You can achieve your requirement by handling QueryCellInfo event as follows:

Code snippet [C#]:

this.grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo);

void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
if (e.Style.ColumnIndex == 2)
bool? chk = e.Style.CellValue as bool?;
if (chk == true)
this.grid.Model[e.Style.RowIndex, 0].Foreground = Brushes.Red;

We have prepared a sample based on this and you can find the sample under the following location:

Sample : http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=Sample_I1189800919.zip

Please let us know if this helps.


Lukas Reusch
Replied On June 15, 2011 01:54 PM UTC


Thank you but the property which decides if the text should be red or not is not the property for the current cell. It's another property which is not a "VisibileColumn"..

Thank you!

Ramesh V [Syncfusion]
Replied On June 16, 2011 09:28 AM UTC

Hi Peter,

Sorry for the Inconvenience caused.
You can achieve your requirement by applying conditional formatting as follows.

Code snippet [XAML]:

We have prepared a sample based on this and you can find the sample under the following location.
Sample: http://www.syncfusion.com/uploads/redirect.aspx?file=99819_f661dc9a.zip&team=testingftp

Please let us know if this helps.

Lukas Reusch
Replied On June 16, 2011 10:17 AM UTC

Thank you very much! It works very well.

But I have a little problem: I only change the Foreground-property. Now if I select a row, this foreground will be overwritten.

Rajasekar [Syncfusion]
Replied On June 17, 2011 01:44 PM UTC

Hi Peter,

Thank you for your update.

You can achieve your requirement by using the below code snippet,

Code snippet[C#]

this.dataGrid.DrawSelectionOptions = GridDrawSelectionOptions.AlphaBlend;

Please let us know if you have any queries.



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