Changing the style dynamically.

5 posts, 0 answers
  1. Pierre
    Pierre avatar
    56 posts
    Member since:
    Jun 2016

    Posted 04 Aug Link to this post

    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.
  2. Pierre
    Pierre avatar
    56 posts
    Member since:
    Jun 2016

    Posted 04 Aug in reply to Pierre Link to this post

    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

  3. DevCraft banner
  4. Stef
    Admin
    Stef avatar
    3047 posts

    Posted 08 Aug Link to this post

    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
  5. Pierre
    Pierre avatar
    56 posts
    Member since:
    Jun 2016

    Posted 11 Aug in reply to Stef Link to this post

    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.


  6. Stef
    Admin
    Stef avatar
    3047 posts

    Posted 12 Aug Link to this post

    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
Back to Top
DevCraft banner