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

Conditional Formatting based on the value of another cell? Possible?

1 Answer 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pawz
Top achievements
Rank 1
Pawz asked on 16 Jun 2008, 03:41 AM
I'd like to set up a conditional format where I have 2 fields - Quantity Required, and Quantity To Order.

If Quantity To Order is less than Quantity Required, I'd like to have the cell light up and show a red background.

I was hoping I could set up a conditional formatting rule that said if Column A is < Column B then.. etc, but that doesn't seem like it wants to work at all.

What's the best way to go about doing this?

1 Answer, 1 is accepted

Sort by
0
Kiril
Telerik team
answered on 17 Jun 2008, 11:59 AM
Hello Pawz,

Yes, you can achieve this functionality. You need to handle the CellFormatting event, which gives you a greater degree of flexibility in setting styles in response to a more complex condition or more operands than made possible by the conditional formatting feature.

For example, the code below sets a style to the cells which satisfy an inequality condition relative to the values in the next row:

        void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)  
        {  
            if (e.CellElement.ColumnIndex == 0)  
            {  
                e.CellElement.DrawFill = false;  
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty);  
                e.CellElement.ResetValue(VisualElement.BackColorProperty);  
 
                if (e.CellElement.Text.Length > e.CellElement.RowInfo.Cells[1].CellElement.Text.Length)  
                {  
                    e.CellElement.DrawFill = true;  
                    e.CellElement.GradientStyle = GradientStyles.Linear;  
                    e.CellElement.NumberOfColors = 2;  
                    e.CellElement.BackColor2 = Color.SkyBlue;  
                    e.CellElement.ForeColor = Color.Red;  
                }  
            }       
        } 

I hope this helps. If you have additional questions, please let me know.

Best wishes,
Kiril
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Pawz
Top achievements
Rank 1
Answers by
Kiril
Telerik team
Share this question
or