views:

1008

answers:

3

Hello,

Does anybody know how to set the title to the form viewer when showing an XtraReport document? The scenario is the following:

I have an XtraReport report configured, I show it calling the ShowPreviewDialog method, a viewer form opens and shows the document. I need to set the title to this viewer form and can't find the property or way to accomplish this.

Thanks in advance.

+2  A: 

I don't believe that the preview form used by the XtraReport object is exposed in such a way that you could simply set the title. However, it is possible to create your own preview form. That would give you ultimate control over how your preview is displayed. Unfortunately, using that approach requires you to invoke the preview differently. You would no longer call myReport.ShowPreviewDialog(). In the example, the report is a private member of the preview form that is created in the form's load event. But I would pass a reference to an existing report object into the form before it loads so you can re-use one print preview form.

Kyle Gagnet
Thanks Kyle! I have a question though... I noticed that you (or the tutorial that you sent) uses the PrintBarManager and the PrintControl, while Pierre propose the use of the PrintRibbon control, what are the advantages/ disadvantages of these two approaches?
Sebastian
I don't know of any particular advantages or disadvantages. It's just a matter of preference. Compare the PrintControl in the tutorial I linked to with this screenshot of a PrintRibbonControl:http://imgur.com/N7WeL.png
Kyle Gagnet
Hey Kyle, I think I found a difference... if you want to use the Ribbon Control, you'll need to buy the XtraBars suite. Apparently, if I just buy an XtraReports license, the Ribbon isn't included.
Sebastian
+2  A: 

In our projects, we always end up creating a ReportViewer form that purpose is to display a XtraReport (or PrintingSystem).

The viewer consist of a normal XtraForm on which we drop a PrintRibbonController. That will automatically create the ribbon bar and the print control.

Then we use a method that bind the report to the viewer:

public partial class ReportViewer : DevExpress.XtraEditors.XtraForm
{
    public ReportViewer()
    {
        InitializeComponent();
    }

    // Used when displaying a single report
    public void SetReport(XtraReport report)
    {
        this.printControl.PrintingSystem = report.PrintingSystem;
        report.CreateDocument();
        this.printControl.UpdatePageView();
    }

    // Used when displaying merged reports
    public void SetReport(PrintingSystem system)
    {
        this.printControl.PrintingSystem = system;
        this.printControl.UpdatePageView();
    }
}

So displaying a report goes like this:

ReportViewer viewer = new ReportViewer();
viewer.SetReport(new EmployeeReport());
viewer.Show();

This approach of creating your own viewer can help you:

  • Manages security by user (for example: a normal user can't change the watermark),
  • Changes the ribbon by removing or adding button to fit your requirements.
Pierre-Alain Vigeant
This is very useful Pierre, thank you! Can you take a look at my comments to Kyle's answer?
Sebastian
+2  A: 

EDIT: Apparently if you do not call CreateDocument it will appear to work sometimes, other times not. So Make sure it is there (it was missing in my first post).

I believe that Kyle's answer is not correct. It appears that you can access the form, it is just not intuitive. As Pierre pointed out, there are valid reasons to create your own form, but if you are find with the default and just want to customize the title then try:

using(var rpt = new XtraReport1())
{
   rpt.PrintingSystem.PrintPreviewFormEx.Text = "My Custom Caption";
   rpt.CreateDocument();
   rpt.ShowPreviewDialog();
}
Andrew Burns
Very interesting Andrew. You're correct, some things are not that intuitive. +1 for you, thanks.
Sebastian
I wonder if there is some way to do it inside de report. I'm interested in having a Base Report with a property ReportTitle and when opening the derived reports assign the prop and let the reports set the title. If there is some way to access the hosting form or something that give me access...
Sebastian