Click here to Skip to main content
15,042,336 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)

I am using visual studio 2019, and doing a project WPF using Telerik UI.
I trying to change cell color of gridview with conditons..

please help me...

What I have tried:

radGridView1.ItemsSource = getdetails_ds.DefaultView;
this.radGridView1.Rows[0].Cells[1].Style.ForeColor = System.Drawing.Color.Red;
Updated 12-Sep-20 4:00am

1 solution

Use built-in conditional formatting functionality:
WPF DataGrid | CellStyleSelector | Telerik UI for WPF[^]
WPF DataGrid | Styling Cells | Telerik UI for WPF[^]
public class StadiumCapacityStyle : StyleSelector 
    public override Style SelectStyle(object item, DependencyObject container) 
        if (item is Club) 
            Club club = item as Club; 
            if (club.StadiumCapacity > 50000) 
                return BigStadiumStyle; 
                return SmallStadiumStyle; 
        return null; 
    public Style BigStadiumStyle { get; set; } 
    public Style SmallStadiumStyle { get; set; } 

    <my:StadiumCapacityStyle x:Key="stadiumCapacityStyle"> 
            <Style TargetType="telerik:GridViewCell"> 
                <Setter Property="Background" Value="Red"/> 
            <Style TargetType="telerik:GridViewCell"> 
                <Setter Property="Background" Value="Yellow" /> 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900