How to display a Devexpress XtraReport on button click in c# wpf application

2.4k views Asked by At

I have created a devexpress XtraReport file in my wpf application. Loaded the data into the report using custom Sql Query in Report wizard. How can i display the report on button click in a xaml usercontrol screen?

Currently i am trying to display as below :

private void GenerateZBReport_Click(object sender, RoutedEventArgs e)
{
    XtraReport report = new XtraReport();
    DocumentPreviewWindow window = new DocumentPreviewWindow();
    window.PreviewControl.DocumentSource = report;
    report.CreateDocument(true);
    window.ShowDialog();
}
3

There are 3 answers

0
Mostafa Shehata On

I think this could help:

var tool = new ReportPrintTool(report);
tool.ShowPreview();

For more information, check this link: Report viewer in XtraReports C#.Net using Winforms Devexpress?

0
e1ecringe On

Use the DocumentPreviewControl located in a UserControl or Window. This is especially helpful in case you want to customize the preview control. This functionality is described in the following help file: Create a Custom Document Preview. Otherwise you can use the PrintHelper class: Invoke a Default Document Preview.

0
k0st1x On

in your code, you've used the XtraReport class, but this class is empty. you should create a typed report class

new XtraReport1()

or load layout by calling

var report = new XtraReport();
report.LoadLayout(filePath);

and only after this you may assign it to viewer and call the CreateDocument() mehtod