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
close icon

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

Hello,

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,
Peter


5 Replies

MA Manikandan Syncfusion Team 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)
{
Console.WriteLine(e.Style.CellValue.ToString());
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.

Regards,
Manikandan




LR Lukas Reusch June 15, 2011 01:54 PM UTC

Hello,

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!



RV Ramesh V Syncfusion Team 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.
Regards,
Ramesh.V





LR Lukas Reusch 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.



RA Rajasekar Syncfusion Team 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.

Thanks,
Rajasekar


Loader.
Live Chat Icon For mobile
Up arrow icon