Set programmatically the name of the form for the viewer in XtraReport

Does anyone know how to set a title to a form viewer when showing an XtraReport document? The scenario is as follows:

I have an XtraReport report configured, I show it a call to the ShowPreviewDialog method, the view form opens and shows the document. I need to set a title for this viewer form and cannot find a property or way to accomplish this.

Thanks in advance.

+2


source to share


6 answers


I don't believe that the preview form used by the XtraReport object expands in such a way that you can just set the title. However, you can create your own preview form . This will give you complete control over how your preview is displayed. Unfortunately, using this approach requires you to invoke the preview differently. You will no longer be calling myReport.ShowPreviewDialog (). In this example, the report is a private member of the preview form that is generated in the form load event. But before submitting, I'll pass the link to the existing report object to the form so that you can reuse the same preview form.



+2


source


EDIT: Apparently if you don't call CreateDocument it will work sometimes and sometimes it won't. So make sure it is there (it was missing in my first post).

I believe Kyle's answer is wrong. It looks like you can access the form, it's just not intuitive. As Pierre pointed out, there are good reasons for creating your own form, but if you find the default and just want to customize the header, try:



using(var rpt = new XtraReport1())
{
   rpt.PrintingSystem.PrintPreviewFormEx.Text = "My Custom Caption";
   rpt.CreateDocument();
   rpt.ShowPreviewDialog();
}

      

+5


source


In our projects, we always create a form ReportViewer

whose purpose is to display XtraReport

(or PrintingSystem

).

The viewer consists of a regular XtraForm on which we throw a PrintRibbonController. This will automatically create a ribbon bar and print controls.

We then use a method that associates the report with 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();
    }
}

      

Thus, the display of the report will look like this:

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

      

This way of creating your own viewer can help you:

  • Manages the security of the user (for example: a regular user cannot change the watermark),
  • Modifies the ribbon by removing or adding a button to suit your requirements.
+2


source


I think there is an article on devexpress support that might help you - Can't change the title of the report header

Its essence:

XtraReport1 rep = new XtraReport1();
            rep.CreateDocument();
            PrintPreviewFormEx form = new PrintPreviewFormEx();
            form.Text = "test";
            form.PrintingSystem = rep.PrintingSystem;
            form.Show(); 

      

+2


source


You can use the ReportPrintTool class to fix your problem:

var report = new MyXtraReport();
ReportPrintTool reportPrintTool = new ReportPrintTool(report);
reportPrintTool.PreviewForm.Text = "Some Text"
report.ShowPreviewDialog();    

      

0


source


I found Pierre's answer very helpful - having your own custom report viewer will really help you control access and the like. I added this code:

 PrintingSystemCommand[] commands = {PrintingSystemCommand.DocumentMap,
                                                   PrintingSystemCommand.Open,
                                                   PrintingSystemCommand.Save};

 this.printControl1.PrintingSystem.SetCommandVisibility(commands, CommandVisibility.None);

      

Of course, you should have links:

using DevExpress.XtraEditors;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting;

      

Thanks again.

0


source







All Articles