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.

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

Thread ID:

Created:

Updated:

Platform:

Replies:

99819 Jun 14,2011 06:24 AM Jun 17,2011 09:44 AM WPF 5
loading
Tags: GridControl
Lukas Reusch
Asked On June 14, 2011 06:24 AM

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


Manikandan [Syncfusion]
Replied On June 15, 2011 09:41 AM

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



Lukas Reusch
Replied On June 15, 2011 09:54 AM

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!


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

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




Lukas Reusch
Replied On June 16, 2011 06:17 AM

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 09:44 AM

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


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.

;