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

How to set the row font by condition in CellFormatting function

2 Answers 31 Views
GridView
This is a migrated thread and some comments may be shown as answers.
c mutex
Top achievements
Rank 1
c mutex asked on 21 Jan 2015, 01:58 AM
radGridView for WinForms 2010 Q1,  thanks very much!

2 Answers, 1 is accepted

Sort by
0
c mutex
Top achievements
Rank 1
answered on 21 Jan 2015, 05:12 AM
I want to change font (color) of any rows  in cellformatting by any condition
0
Todor Vyagov
Telerik team
answered on 21 Jan 2015, 02:15 PM
Hello,

Thank you for writing.

You can change the row font using the CellFormatting event. Any other styles can also be applied.
Font font = new Font("Times", 16);
 
private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.CellElement.RowInfo.Cells["ProductName"].Value != null)
    {
        if (e.CellElement.RowInfo.Cells["ProductName"].Value.ToString().Contains("a"))
        {
            e.CellElement.ForeColor = Color.Red;
            e.CellElement.Font = font;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.FontProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

You can find more information about cell formatting here: Formatting Cells
Another way to format cells and rows is to use data conditions: Conditional Formatting Cells

I hope this helps.

Regards,
Todor
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
c mutex
Top achievements
Rank 1
Answers by
c mutex
Top achievements
Rank 1
Todor Vyagov
Telerik team
Share this question
or