Articles in this section
Category / Section

How to print WPF DataGrid (SfDataGrid) with DetailsView?

1 min read

You can print the WPF DataGrid (SfDataGrid) by including DetailsView with the help of PdfViewer and PDF exporting. For this, you have to export the WPF DataGrid (SfDataGrid) to PDF and load the exported PDF in PdfViewer. Then you can print the PDF using PdfViewer.Print() method.

C#

private void Button_Click(object sender, RoutedEventArgs e)
{
    PdfExportingOptions options = new PdfExportingOptions();
    options.ExportDetailsView = true;
    var document = sfdatagrid.ExportToPdf(options);
    MemoryStream stream = new MemoryStream();
    document.Save(stream);
    PdfLoadedDocument ldoc = new PdfLoadedDocument(stream);
    PdfViewerControl pdfViewer = new PdfViewerControl();
            
    Window window = new Window();
    Grid grid = new Grid();
    window.Content = grid;
 
    //Load the PdfDocument in to PdfViewer
    pdfViewer.Load(ldoc);
    grid.Children.Add(pdfViewer);
    window.Show();
}

 

Print the WPF DataGrid with details view

View sample in GitHub.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied