Conditional formatting - Win App

6 posts, 0 answers
  1. Claude
    Claude avatar
    63 posts
    Member since:
    Apr 2009

    Posted 22 Apr 2014 Link to this post

    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.
  2. Ralitsa
    Admin
    Ralitsa avatar
    190 posts

    Posted 23 Apr 2014 Link to this post

    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.
     
  3. Alex Dybenko
    Alex Dybenko avatar
    157 posts
    Member since:
    Jan 2005

    Posted 19 Nov 2019 in reply to Ralitsa Link to this post

    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

     

  4. Dimitar
    Admin
    Dimitar avatar
    23 posts

    Posted 21 Nov 2019 Link to this post

    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.
  5. Alex Dybenko
    Alex Dybenko avatar
    157 posts
    Member since:
    Jan 2005

    Posted 25 Nov 2019 in reply to Dimitar Link to this post

    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

     

  6. Dimitar
    Admin
    Dimitar avatar
    23 posts

    Posted 26 Nov 2019 Link to this post

    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.
Back to Top