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

summary change color Based on condition

2 Answers 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mahmoud
Top achievements
Rank 1
Mahmoud asked on 09 Mar 2015, 08:59 AM
I need a method to compare the results between and on the basis that I change the color

Probably this picture shows

2 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 10 Mar 2015, 01:36 PM
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.

 
0
Mahmoud
Top achievements
Rank 1
answered on 11 Mar 2015, 01:24 PM
Hello Stefan ,

Thank you for answer
Tags
GridView
Asked by
Mahmoud
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Mahmoud
Top achievements
Rank 1
Share this question
or