i have one GridView that contains Column Name "Day1", "Day2" ....to "Day31".
Now i want to change Cell Background and ForeColor Based On Value.
For All the 31 Columns
if cell value = "P" then Green Background and forecolor white.
how can i do this.
Please Help me.
4 Answers, 1 is accepted
You can check our online documentation on how to use a CellStyleSelector here. The "Style Selectors -> Cells" WPF demo would also be helpful for you.
Regards,
Didie
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Hi,
I have taken a look at the documentation and the demos (Silverlight) but in all cases your CellStyleSelector is based on a business object with a specific property in the column to which the style needs to be applied. In my case my business object as an array of values which I want to display using the same CellStyleSelector. I build the columns in the code behind. So to use your method my CellStyleSelector must be aware of the specific column in question. Any pointers?
Regards
Renier
You can find the column associated with the cell passed as the container argument. The code to access it would be similar to this one:
GridViewCell cell = container
as
GridViewCell;
var currentColumn = cell.Column
as
GridViewDataColumn;
My suggestion is to work with the bound data item and CellStyleSelection and not with the visual elements directly. As RadGridView is a virtualized control, its elements are reused as they are brought in and out the view area. You can also check our online documentation explaining how the UI virtualization works.
Regards,
Dimitrina
Telerik
I found an easier approach using a single ValueConverter (not aware of the DataContext)
I think this is usually better than the heavy StyleSelector approach, you can also reuse the ValueConverter for different columns more easily.
Set the GridColumns CellStyle to
<
Style
x:Key
=
"IsSentCellStyle"
TargetType
=
"telerik:GridViewCell"
BasedOn
=
"{StaticResource GridViewCellStyle}"
>
<
Style.Setters
>
<
Setter
Property
=
"Background"
Value
=
"{Binding IsSent, Converter={controls:FalseToRedBrushConverter}}"
/>
</
Style.Setters
>
</
Style
>