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

2 posts, 0 answers
  1. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 15 Jun 2008 Link to this post

    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?
  2. Kiril
    Kiril avatar
    158 posts

    Posted 17 Jun 2008 Link to this post

    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;  
                    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,
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top