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

changing row color based on data value

8 Answers 630 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
hchattaway
Top achievements
Rank 1
hchattaway asked on 25 Jun 2007, 07:44 PM
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

8 Answers, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 26 Jun 2007, 02:04 PM
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
0
hchattaway
Top achievements
Rank 1
answered on 26 Jun 2007, 02:46 PM
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

0
Ivan
Telerik team
answered on 26 Jun 2007, 04:49 PM
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
0
hchattaway
Top achievements
Rank 1
answered on 26 Jun 2007, 05:27 PM
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

0
Vassil Petev
Telerik team
answered on 27 Jun 2007, 02:15 PM
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
0
Ulrich Fiege
Top achievements
Rank 1
answered on 05 Aug 2010, 05:42 PM
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 ....


0
Joel
Top achievements
Rank 2
answered on 05 Aug 2010, 07:26 PM
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.
0
Ulrich Fiege
Top achievements
Rank 1
answered on 06 Aug 2010, 09:03 AM
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 ...
Tags
General Discussions
Asked by
hchattaway
Top achievements
Rank 1
Answers by
Ivan
Telerik team
hchattaway
Top achievements
Rank 1
Vassil Petev
Telerik team
Ulrich Fiege
Top achievements
Rank 1
Joel
Top achievements
Rank 2
Share this question
or