How to set the row font by condition in CellFormatting function

3 posts, 0 answers
  1. c mutex
    c mutex avatar
    5 posts
    Member since:
    Jan 2010

    Posted 20 Jan 2015 Link to this post

    radGridView for WinForms 2010 Q1,  thanks very much!
  2. c mutex
    c mutex avatar
    5 posts
    Member since:
    Jan 2010

    Posted 20 Jan 2015 in reply to c mutex Link to this post

    I want to change font (color) of any rows  in cellformatting by any condition
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Todor Vyagov
    Admin
    Todor Vyagov avatar
    31 posts

    Posted 21 Jan 2015 Link to this post

    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.

     
Back to Top