changing row color based on data value

9 posts, 0 answers
  1. hchattaway
    hchattaway avatar
    67 posts
    Member since:
    Feb 2007

    Posted 25 Jun 2007 Link to this post

    Hello!
    Been playing with the reporting tool and have made a lot of progress quickly. One thing I would like to do though, is change the row color based on the value of a field in that row. I know styles are used heavily in this product and I am sure that it can be done... any ideas?

    Thanks!
    Harold Chattaway

  2. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 26 Jun 2007 Link to this post

    Hi hchattaway,

    Thank you for your question. We are glad to hear that your work is progressing nicely.

    All you need to do to achieve your goal is to handle ItemDataBound event for the needed report item. Inside this handle you can change the Style property of the sender's parent.

    I have attached a sample solution which should help you further. In it you will find a ClassLibrary with one report (where the row background respects the value of rightmost text box), and two application projects (winform and website) to test the report's behavior. All the styling action is inside the textBox5_ItemDataBound method found in Report1.cs file.
     

    All the best,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. DevCraft banner
  4. hchattaway
    hchattaway avatar
    67 posts
    Member since:
    Feb 2007

    Posted 26 Jun 2007 Link to this post

    Hi Ivan

    This is awesome, just what I wanted! Thanks!
    One more question on this:
    Still learning the databinding ins and outs...

    The line:
     private void InitializeComponent()
            {
                this.table = new DummyDataSource.MyDataTable();

    is in the section for auto-generated code in report1.designer.cs. However, I do not see in the designer, where this association is made. Could you elaborate on this? How is this done through the designer?

    Thanks for your effort!
    Harold

  5. Ivan
    Admin
    Ivan avatar
    519 posts

    Posted 26 Jun 2007 Link to this post

    Hi Harold,

    The code related to the dummy data source is written by hand. This is the quick way to design reports, but unfortunately, it is not available in the designer.

    If you want to use such a coding style, please note these these lines of code:

    in the report class
    private MyDataTable table;

    and in the InitializeComponent method.

    this.table = new DummyDataSource.MyDataTable();
    ...
    this.DataSource = this.table;


    If you shorten the code to only one line:
    this.DataSource = new DummyDataSource.MyDataTable();

    the next time you save the report file from the report designer, the code serializer will remove it.
     

    Sincerely yours,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. hchattaway
    hchattaway avatar
    67 posts
    Member since:
    Feb 2007

    Posted 26 Jun 2007 Link to this post

    Ok, thanks Ivan! That's what I thought, just wanted to make sure not missing something!

    You guys have awesome tech support. BTW, the video on the site that goes over the report writer was great. That conveyed more info then reading a 100 posts. Thanks for that. More should be made on data binding specifically. That would go over big I am sure.

    Harold

  7. Vassil Petev
    Admin
    Vassil Petev avatar
    1765 posts

    Posted 27 Jun 2007 Link to this post

    We are glad to have helped, hchattaway, thank you for the rewarding words! As to the videos, we are working on creating new ones at the moment and we will surely provide one or two on  data binding. Stay tuned!


    All the best,
    Rob
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Ulrich Fiege
    Ulrich  Fiege avatar
    62 posts
    Member since:
    Sep 2005

    Posted 05 Aug 2010 Link to this post

    hello,
    I am using textBox5_ItemDataBound event to check for a special value and so it changes the backcolor of the specified cell.
    My problem is how can i access the other textboxes in the row when the event fires? I will also change the style from all other
    textboxes in current row and not only from textBox5?

    Thanks ....


  9. Joel
    Joel avatar
    166 posts
    Member since:
    Oct 2006

    Posted 05 Aug 2010 Link to this post

    Try conditional formatting.  RIght click on the box in question, select conditional formatting,   New Rule.  Use =Fields.xxxx for the field you want to evaluate, instead of the textbox name, and set your value, then you can set a style for that condition.  You can only do one item at a time, unlike a normal style, but it works great.
  10. Ulrich Fiege
    Ulrich  Fiege avatar
    62 posts
    Member since:
    Sep 2005

    Posted 06 Aug 2010 Link to this post

    Thank you,but this not the answer of my problem.
    Here is a code snipped to show what i mean:
    Dim txtPosition As Telerik.Reporting.Processing.TextBox = DirectCast(sender, Telerik.Reporting.Processing.TextBox)
    If txtPosition.Text.Contains("-/-") Then
        txtPosition.Style.BackgroundColor = Color.Red
        '->> Works OK 
        Dim table As Telerik.Reporting.Processing.Table = DirectCast(txtPosition.Parent, Telerik.Reporting.Processing.Table)
        Dim tx8 As Telerik.Reporting.Processing.TextBox = DirectCast(table.ChildElements.Find("TextBox8", True)(0), Telerik.Reporting.Processing.TextBox)
        tx8.Style.BackgroundColor = Color.Blue
        '->> Color is only in firstRow not in same row like the red one
    End If

    I have only one textbox in the row with the special value for changing the rowcolor and i can't change
    the other cells to red in this row from this TextBox5_ItemDataBound.
    I think the problem is the parent position but i need the current row.
    How can i slove this?
    Thank you ...
Back to Top
DevCraft banner