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

Conditional formatting - Win App

5 Answers 236 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Claude asked on 22 Apr 2014, 06:30 PM
I am using conditional formatting on multiple columns, setting the background color based on the value in the cell.

Conditions are if value of cell is Between 0.23 and 3.41, set background color to Yellow.

This works well until in one column the cell value >= 10.0 and it starts to highlight the cell again.

5 Answers, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 23 Apr 2014, 11:55 AM
Hi Claude,

Thank you for contacting us. 

If you want to apply one conditional formatting rule to two or more columns, you need to use ExpressionFormattingObject. The expression could refer to data from more than one column. Please take a look at the following example: 
ExpressionFormattingObject expressionCondition = new ExpressionFormattingObject("MyCondition", "UnitPrice > 0.23 AND Price > 0.23 AND UnitPrice < 3.41 AND Price < 3.41", true);
expressionCondition.RowBackColor = Color.Yellow;
this.radGridView1.Columns["Price"].ConditionalFormattingObjectList.Add(expressionCondition);

You can find more information about ExpressionFormattingObject in our help documentation, section Expression based formatting objects.

I attached a sample demo project to demonstrates you the formatting.  

Should you have further questions, I would be glad to help. 

Regards,
Ralitsa
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Alex Dybenko
Top achievements
Rank 2
answered on 19 Nov 2019, 08:25 AM

Hi,

this sample works ok, but how can I use functions in expression? if I make expression like:

TRIM(TextBoxColumn)='test' - i got an exception

 

Thanks

Alex

 

0
Dimitar
Telerik team
answered on 21 Nov 2019, 02:41 PM

Hello Alex,

Indeed, using TRIM() expressions via code results in an exception. I have tested the same operation through "Conditional Formatting Rules Manager" form, setting the following expression: TRIM(ContactName) = 'Maria Anders' and it worked OK. It turns out that TRIM() expressions are not parsed correctly when they are set in code.

Therefore, I have logged a bug in our feedback portal. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.

I have also updated your Telerik points.

As a workaround you could subscribe to RadGridView.CellFormatting event and format your cells as follows:

private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.Row is GridViewDataRowInfo && e.Column.Name == "ContactName")
    {
        if (e.CellElement.Text.Trim() == "Maria Anders")
        {
            e.CellElement.DrawFill = true;
            e.CellElement.GradientStyle = GradientStyles.Solid;
            e.CellElement.BackColor = Color.Aqua;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        }
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
    }
}

In this scenario if there is a cell with "Text.Trim() == 'Maria Anders'"the CellBackColor will be set to Aqua.

I hope you find this information useful.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alex Dybenko
Top achievements
Rank 2
answered on 25 Nov 2019, 08:07 AM

Hi Dimitar,

on my side it does not work even with Conditional Formatting Rules Manager, it can accept expression, but apply formating only to one cell, .e.g. try condition like  Trim(ContactTitle) = 'Accounting Manager' 

Anyway, hope we get enough votes and bug will be fixed

Alex

 

0
Dimitar
Telerik team
answered on 26 Nov 2019, 09:01 AM

Hello Alex,

I could not reproduce your experience with Conditional Formatting Rules Manager. Please see the attachment. Feel free to use the provided workaround until we fix the bug. In case the issue persists please open up a support ticket and send us your project so that we can further test it.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Claude
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Alex Dybenko
Top achievements
Rank 2
Dimitar
Telerik team
Share this question
or