This is a migrated thread and some comments may be shown as answers.

How to dynamically style cells/rows?

2 Answers 33 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Todd Davis
Top achievements
Rank 1
Todd Davis asked on 08 Apr 2010, 02:53 PM
I have a need to occasionally set some styling based on the value of a cell (for example, if the Status cell is "Normal" then leave it alone, but if the Status cell is "Emergency" then turn the text red).

I attempted to handle this by using the RowLoaded() event and querying the data there, and setting the values, i.e.

// Get a handle to both the data and the element 
var data = e.DataElement as WLStudyData; 
var row = e.Row as GridViewRow; 
 
if (data == null || row == nullreturn
 
if (data.Status == Status.Emergency.ToString()) 
    row.Cells[4].Foreground = new SolidColorBrush(Colors.Red); 

This "sort of" works. The problem is that as I scroll through the records, the Forecolor changes on other items, ones that are NOT marked as Emergency.

In order to better explain, here is a short video of the problem occurring. Using the code above, only items with a status of StatEmergent should be Red (Stroke is Blue). Look at the top items that are initially black. Watch as I scroll down, then scroll up again. You will see the red text start to "bleed" onto rows where it doesn't belong

http://screencast.com/t/NGYxMjcyNm

I was hoping I could perhaps set the styling using the CellStyle property in XAML, however I am not sure how to make that dependent on the cell value?



2 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 08 Apr 2010, 02:58 PM
Hello Todd,

Please check this blog post for more info about how to achieve this using IValueConverter. Recently we introduced also Style and DataTemplate selectors - you can check my blog post for more info.

Greetings,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Todd Davis
Top achievements
Rank 1
answered on 08 Apr 2010, 05:54 PM
Wow, very powerful feature - that's exactly what I was looking for, thank you.
Tags
GridView
Asked by
Todd Davis
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Todd Davis
Top achievements
Rank 1
Share this question
or