summary change color Based on condition

3 posts, 1 answers
  1. Mahmoud
    Mahmoud avatar
    10 posts
    Member since:
    Mar 2015

    Posted 09 Mar 2015 Link to this post

    I need a method to compare the results between and on the basis that I change the color

    Probably this picture shows
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 10 Mar 2015 Link to this post

    Hello Mahmoud,

    Thank you for writing.

    You can use the ViewCellFormatting event to do the desired formatting:
    void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        GridSummaryCellElement summaryCell = e.CellElement as GridSummaryCellElement;
        if (summaryCell != null)
        {
            int firstValue = Convert.ToInt32( e.Row.Cells["A"].Value);
            int secondValue = Convert.ToInt32(e.Row.Cells["B"].Value);
     
            if (e.Column.Name == "A" &&  firstValue > secondValue)
            {
                e.CellElement.ForeColor = Color.Red;
            }
            else
            {
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
            }
        }
    }

    More information on formatting can be found here: Formatting Cells.

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mahmoud
    Mahmoud avatar
    10 posts
    Member since:
    Mar 2015

    Posted 11 Mar 2015 in reply to Stefan Link to this post

    Hello Stefan ,

    Thank you for answer
Back to Top