ActiveReports 18 .NET Edition
Developers / Work with Reports using Code / Page/RDLX Report / Apply Styles through Code
In This Topic
    Apply Styles through Code
    In This Topic

    The following steps set a style sheet source and apply style to a TextBox control. 

    1. In Visual Studio, create a new Page Report Application or open an existing one.
    2. On the Form.cs or Form.vb that opens, double-click the title bar to create the Form_Load event.
    3. Add the following code inside the Form_Load event.
      Visual Basic.NET code. Paste INSIDE the Form Load event.
      Copy Code
      'Path and Name of the loaded PageReport
      Dim filePath As String = "C:\SampleReport.rdlx"
      Dim pageReport As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(filePath))
      Dim reportDocument As New GrapeCity.ActiveReports.Document.PageDocument(pageReport)
      
      ' Set the style sheet source and value using external style sheets
      reportDocument.PageReport.Report.StyleSheetSource = GrapeCity.ActiveReports.PageReportModel.StyleSheetSource.External
      reportDocument.PageReport.Report.StyleSheetValue = "C:\ExternalStyle.rdlx-styles"
      
      ' Set the style sheet source and value using embedded style sheets
      reportDocument.PageReport.Report.StyleSheetSource = GrapeCity.ActiveReports.PageReportModel.StyleSheetSource.Embedded
      reportDocument.PageReport.Report.StyleSheetValue = "EmbeddedStylesheet1
      
      ' Add a Textbox control and apply style
      Dim text As New GrapeCity.ActiveReports.PageReportModel.TextBox()
      text.Value = "Sample Text"
      text.Style.StyleName = "Style1"
      pageReport.Report.Body.ReportItems.Add(text)
      viewer1.LoadDocument(reportDocument)
      

      C# code. Paste INSIDE the Form Load event.
      Copy Code
      //Path and Name of the loaded PageReport
      string filePath = @"C:\SampleReport.rdlx";
      GrapeCity.ActiveReports.PageReport pageReport = 
      new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(filePath));
      GrapeCity.ActiveReports.Document.PageDocument reportDocument = 
      new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
      
      // Set the style sheet source and value using external style sheets
      reportDocument.PageReport.Report.StyleSheetSource = GrapeCity.ActiveReports.PageReportModel.StyleSheetSource.External;
      reportDocument.PageReport.Report.StyleSheetValue = @"C:\ExternalStyle.rdlx-styles";
      
      // Set the style sheet source and value using embedded style sheets
      reportDocument.PageReport.Report.StyleSheetSource = GrapeCity.ActiveReports.PageReportModel.StyleSheetSource.Embedded;
      reportDocument.PageReport.Report.StyleSheetValue = "EmbeddedStylesheet1";
      
      // Add a Textbox control and apply style
      GrapeCity.ActiveReports.PageReportModel.TextBox text = 
      new GrapeCity.ActiveReports.PageReportModel.TextBox();                      
      text.Value = "Sample Text";
      text.Style.StyleName = "Style1";
      pageReport.Report.Body.ReportItems.Add(text);                                                                     
      viewer1.LoadDocument(reportDocument);
      
             

       

    See Also

    Report Authors