The requested page is not available for the requested platform. You are viewing the content for Default platform.

Store Report Style Sheets

  • 3 min to read

This tutorial describes how to create and save report style sheets at design time within Visual Studio, and conditionally load them at runtime.

How to - CreateStyleSheets_4

Create and Save Style Sheets

  1. To create a table report in this tutorial, start with a report that is bound to the "Products" table of the sample Northwind database (the nwind.mdb file is included in the XtraReports installation). To learn more about binding a report to a data source, see Provide Data to Reports. In this tutorial, you will start with the following report layout.

    HowTo_CreateTableReport_2

  2. To add a new style sheet, switch to the Report Explorer, right-click the Styles node or its sub-node and in the invoked context menu, select Add Style.

    odd-style-add

  3. Then, right-click the newly added style and select Edit Styles... in the context menu. In the invoked Styles Editor, specify the style name ("myOddStyle"), and save it as three separate style sheets (myStyle_Rose.repss, myStyle_Yellow.repss and myStyle_Blue.repss) in the Styles folder of the application's directory. Each style sheet has a different BackColor setting.

    How to - CreateStyleSheets_1

    After saving the style sheets, click Close.

  4. To assign a style to the XRTable in the Detail band, expand its XRControl.Styles property in the Properties window, and set the OddStyle property to myOddStyle.

    How to - CreateStyleSheets_2

Load Style Sheets

  1. Add a parameter to the report. To do this, right-click the Parameters section in the Field List window, and choose Add Parameter in the invoked context menu.

    Shared_FieldList_AddParameter

  2. In the invoked dialog, adjust the properties of the parameter as shown in the following image.

    How to - CreateStyleSheets_3

    Click OK to exit the dialog.

  3. Programmatically assign the style sheets to the report depending on the parameter value. To do this, handle the report's XRControl.BeforePrint event in the following way.

    using System.Windows.Forms;
    using DevExpress.XtraReports.UI;
    // ...
    
    private void XtraReport1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
        string sheetName = "";
    
        // Define a relative start-up path, so that styles are loaded 
        // regardless of the location of the application. 
        string path = Application.StartupPath + @"\..\..\Styles\";
    
        // Define the appropriate style sheet based on the selected parameter value. 
        switch((int)OddStyle.Value) {
            case 0:
                sheetName = "myStyle_Rose.repss";
                break;
            case 1:
                sheetName = "myStyle_Yellow.repss";
                break;
            case 2:
                sheetName = "myStyle_Blue.repss";
                break;
        }
    
        // Set the report's StyleSheetPath property to specify the report's style sheet.           
        ((XtraReport)this).StyleSheetPath = path + sheetName;          
    }
    
See Also