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

Changing the style dynamically.

4 Answers 482 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 04 Aug 2016, 09:54 AM
Hi,

I want to change the style / the theme of my report based on the User.
All my User have a UserGroup. My UserGroup has custom style.
All this information are in the DB.
UserStyle: ID | ID UserGroup | LOGO | Style 1 | Color 1 | ect..

I want change my report style with those informations.
I know it is possible to give my item a style name.
But Can i define it in the main report Code behind.

Bonus: Can I do this Only once for the Main Report?

Basically using Style Name as a CssClass.

4 Answers, 1 is accepted

Sort by
0
Pierre
Top achievements
Rank 1
answered on 04 Aug 2016, 01:00 PM

This is a not tested solution, YET. and i still have issue.
Style in a telerik report can be define in a StyleRules.
See -> http://docs.telerik.com/reporting/style-creating-style-rules

In order to manage the theme based on the user I can use a ReportParameter.

Telerik.Reporting.Drawing.StyleRule styleRule1 = new Telerik.Reporting.Drawing.StyleRule();
styleRule1.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
new Telerik.Reporting.Drawing.StyleSelector("MyStyle")});
 
if( reportParameter1.Value == "StyleUser1")
{
    styleRule1.Style.Padding.Left = Telerik.Reporting.Drawing.Unit.Point(2D);
    styleRule1.Style.Padding.Right = Telerik.Reporting.Drawing.Unit.Point(2D);
    styleRule1.Style.BackgroundColor = System.Drawing.Color.Blue;
    styleRule1.Style.Color = System.Drawing.Color.White;
    styleRule1.Style.Font.Bold = true;
    styleRule1.Style.Font.Name = "Segoe UI";
}
else {
    //default style
}

I can add the Style name to you element from the designer or from the constructor.
this way:
this.textBox2.StyleName = "MyStyle";

Ican create my style rules in the designer and only assign the style to the component in my initialise component.
if( reportParameter1.Value == "StyleUser1")
{
    this.textBox1.StyleName = "MyStyle";
    this.textBox2.StyleName = "MyStyle";
    this.textBox3.StyleName = "MyStyle";
}
else {
    //default style
}

But i still don't find how to access SubReport Elements from the main reports.
I have try

var Plop = this.Items.Find("textBox17", true);

var xyz = this.SR_CLIENT.Items.Find("textBox17", true);

textBox1.Value = Plop.GetLength(0).ToString();
textBox2.Value = Plop.Length.ToString();
textBox3.Value = xyz.GetLength(0).ToString();
textBox4.Value = xyz.Length.ToString();
I really dont want to define my StyleRule in my 23 SubReport.

regards,
Pierre LEBON

0
Stef
Telerik team
answered on 08 Aug 2016, 11:16 AM
Hi Pierre,

You can use external stylesheets and load them depending on the user. The StyleName properties of items can point to the same style, that will differ in stylesheets.
More details and an example of changing dynamically stylesheets is illustrated in the Dynamically change Stylesheets in Report Designer forum thread.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Pierre
Top achievements
Rank 1
answered on 11 Aug 2016, 02:41 PM

Hi Stef,

Thanks for this great answer.
I was using The Designers code to do it.
But with external StyleSheet its now clear and easy to maintain.
I dont know how i didn't come across this in my research.

I would like to submit few idea about the docs and the forum, but i can't find where they are on the feedback portal.

 

Regards,
Pierre.


0
Stef
Telerik team
answered on 12 Aug 2016, 03:38 PM
Hi Pierre,

A Product Feedback ticket or post in our feedback portal are the best way to do it. Any suggestions for documentation improvement can be submitted in support tickets and forums as well.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Pierre
Top achievements
Rank 1
Answers by
Pierre
Top achievements
Rank 1
Stef
Telerik team
Share this question
or