Report Level Conditional Formatting

7 posts, 1 answers
  1. Chris
    Chris avatar
    10 posts
    Member since:
    Jul 2011

    Posted 08 Mar 2012 Link to this post

    I'm trying to conditionally format the text of all fields showing on my report, if the value is a specific string value. Example, if the field has a value of "No" then i would leave it alone, if it was "Yes" it would have a text font color of red. I don't want to declare this for each field, I want to write one logical statement that can check the field value and if it meets a certain criteria, then it would format the style on the textbox that contains that field reference.


    Is there a way to do this through design time dialogues or programatically?
  2. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 13 Mar 2012 Link to this post

    Hello Brandon,

    Conditional formatting on multiple report items is supported i.e. you can select several TextBoxes and click on the ConditionalFormatting in the property grid to open the formatting dialog where you would apply the desired condition. This way the formatting rule would be applied to all selected items and you do not have to define it separately for each and every item.

    While you can't reuse one conditional formatting from the report designer once it has been defined, you can do so by manually creating the formatting rule in the report constructor, this way you can always add the formatting rule to the ConditionalFormatting collection of any new item you need.
    As you're already utilizing an user function, you can include the ReportItem as argument to that function and get its value. Then if the value is 'Yes', you could return an appropriate color and use the user function as Value for a binding expression. For sample implementation, please check the ProductCatalog demo report where we use ColorFromName user function to specify a color via Bindings.

    There is definitely a room for improvement by changing how styles are applied, so that an already defined StyleName can be used in binding or even in a conditional formatting, which would make it really reusable. These improvements are already logged in our system and would be considered for subsequent version of the product.

    All the best,
    Steve
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
  3. DevCraft banner
  4. Chris
    Chris avatar
    10 posts
    Member since:
    Jul 2011

    Posted 13 Mar 2012 Link to this post

    I am in need of one more piece of information. I can select all of the fields to use in the conditional formatting, but the way your conditional formatting dialogue works is by defining the field to be looked at, and the expression/logic for that field. Since I'm actually writing the statement for a collection of fields, I can't specify which field to look at - so instinctively i would write Fields.Value, expecting each field to return a value and that is what is used in the expression, however there is no "value" property of the fields object so I'm not sure how to reference the field generically.

    This is how my conditional formatting would read (Formatting applies to all fields within my selection);

    if the value of the field is equal to 100000000 then change text color to red, if the value is equal to a different value, I wan't to leave it alone.


    Bottom line is, I don't want to specify this for each field individually if possible.
  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 14 Mar 2012 Link to this post

    Hi Brandon,

    Will continue to post here, so that it helps the community should somebody else have certain questions:

    My previous post already contains the answer to your question - you can get the respective value for each detail record by using the ReportItem Global Objects in the conditional formatting expression as argument to your user function.

    Regards,
    Steve
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
  6. Chris
    Chris avatar
    10 posts
    Member since:
    Jul 2011

    Posted 14 Mar 2012 Link to this post

    Steve,
    If I use the global ReportItem object (in the Expression column of the conditional formatting dialogue) to compare to a value of 100000000 , I get the following error;

    "An error has occured while processing Textbox 'textbox29': Cannot perform "=" operation on Telerik.Reporting.Processing.TextBox and system.Int32."


    So the report item is returning the textbox, not the value that's held within the textbox. I tried adding .value to ReportItem - this gets rid of my error but the conditional formatting doesn't format anything (after looking through the api, i don't see any value member on the reportitem object anyway)


    I'm obviously missing something here but your responses aren't specific enough for me to figure this out...I'd appreciate some further detail on the matter.


    Thanks

  7. Chris
    Chris avatar
    10 posts
    Member since:
    Jul 2011

    Posted 14 Mar 2012 Link to this post

    Okay now that I've re-read the thread I understand what I was missing, you were saying I could get to the reportitem value from within my user function, so I will look into that possibility. However, I'm still curious if there is any way to get to the value of the report item using only the reporting expression builder.

     I'm wrapping specific questions in 1 of 5 slightly different user functions, because different questions use different option sets so my linq query differs slightly for each item (I need to pass in the name of the field of the report item in order to turn those 5 functions into one, but I wasn't able to determine how to do so, since all i could really tell is that we are passing in the value of the field by wrapping it in the user function, so I could use some guidance on that if you could be so kind), but there may be a way for me to write this into each function, I'll look into that in the meantime


    Thanks
  8. Peter
    Admin
    Peter avatar
    1611 posts

    Posted 19 Mar 2012 Link to this post

    Hi Brandon,

    In general in our tests ReportItem.Value used in an expression is working correctly and returns the report item's value. Still you can debug the result by passing the ReportItem object itself to the user function to make sure the value is the one you expect.

    We are not sure what you refer by the name of the field. If you need to access the Textbox.Name you can use ReportItem.Name. However if you refer to the definition Textbox.Value (=Field.MyField), the definition value is not available in expressions. Thus our suggestion is to write the required user function argument directly in the expression.

    Greetings,
    Peter
    the Telerik team
    NEW in Q1'12: Telerik Report Designer (Beta) for ad-hoc report creation. Download as part of Telerik Reporting Q1 2012. For questions and feedback, use the new Telerik Report Designer Forum.
Back to Top
DevCraft banner