We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Exporting Unbound Rows from SfDataGrid to PDF

I am using a SfDataGrid which DataSource is bound to an ObservableCollection.
For further information in terms of data evaluation I added a TableSummaryRow and serveral UnboundRows.
The complete SfDataGrid should be able to be exported to Excel and also to PDF.
As mentionend in Your Documentation UnboundRows are not exported by Default.
Therefor I edited the DataGridExcelExportingOption and DataGridPdfExportOption as following code snippets show:

            DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
            var excelEngine = excelExport.ExportToExcel(sfDataGrid, new DataGridExcelExportingOption()
                ExportTableSummary = true,
                ExportUnboundRows = true,
            var workbook = excelEngine.Excel.Workbooks[0];
            MemoryStream stream = new MemoryStream();

            //Holen der plattformspezifischen Implementierung des Interfaces mittels DependecyService
            DependencyService.Get<IFileOperator>().Save("DataGrid.xlsx", "application/msexcel", stream);

            DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
            MemoryStream stream = new MemoryStream();
            var exportToPdf = pdfExport.ExportToPdf(sfDataGrid, new DataGridPdfExportOption()
                ExportTableSummary = true,
                //ExportUnboundRows = true, //!!!"NullReference"!!!
                FitAllColumnsInOnePage = true,

            //Holen der plattformspezifischen Implementierung des Interfaces mittels DependecyService           
            DependencyService.Get<IFileOperator>().Save("DataGrid.pdf", "application/pdf", stream);

While the Excel-Export works perfectly fine (showing TableSummaryRow and UnboundRow), the PDF-Export just is able to export the TableSummaryRow.
Trying to export the UnboundRow throws an exception:

$exception{System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportUnboundRowToPdf(SfDataGrid dataGrid, PdfGridRow pdfRow, DataGridPdfExportOption exportOption, GridUnboundRow gridUnboundRow, ExportCellType cellType) at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportUnboundRowsToPdf(SfDataGrid dataGrid, PdfGrid pdfGrid, DataGridPdfExportOption exportOption, UnboundRowsPosition position, Boolean belowSummary, ObservableCollection`1 unBoundRows) at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportToPdfGrid(SfDataGrid dataGrid, ICollectionViewAdv collectionView, DataGridPdfExportOption exportOption, PdfDocument pdfDocument) at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportToPdf(SfDataGrid dataGrid, ICollectionViewAdv collectionView, DataGridPdfExportOption exportOption) at Syncfusion.SfDataGrid.XForms.Exporting.DataGridPdfExportingController.ExportToPdf(SfDataGrid dataGrid, DataGridPdfExportOption exportOption) at XSyncfusionContentViews.ViewModels.XTableOperatorButtonsViewModel.ExportToPDF(SfDataGrid sfDataGrid) at XSyncfusionContentViews.Views.XTableOperatorButtonsView.Pdf_Clicked(Object sender, EventArgs e) at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked() at Xamarin.Forms.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager) at Xamarin.Forms.Button.SendClicked() at Xamarin.Forms.Platform.UWP.ButtonRenderer.OnButtonClick(Object sender, RoutedEventArgs e)}System.NullReferenceException

I am using the following versions of NuGet-Packages:

- Syncfusion.Xamarin.DataGridExport
- Syncfusion.Xamarin.Pdf
- Syncfusion.Xamarin.SfDataGrid
- Syncfusion.Xamarin.XlsIO

I would be glad, if You can help me find a solution for this particular problem. I am looking forward to hear from You soon.

Kind regards


6 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team May 6, 2019 10:40 AM UTC

Hi Julian, 
Thank you for contacting Syncfusion support.

We have already found and fixed the mentioned issue “Throws exception when exporting the DataGrid with UnBoundRows to PDF” in Xamarin.Forms. The issue fix has been included the issue fix in our weekly NuGet update version and is available for download (nuget.org). This issue fix will be including in 2019 Volume 1 Service pack release which is expected to be available by next of May 2019.  
Please let us know, if you have any concern. 
Subburaj Pandian V  

JU Julian May 6, 2019 11:08 AM UTC

Hi Subburaj Pandian V,

I updated all my used NuGet-Packages to version (newest stable version), but the problem remains the same :/



SP Subburaj Pandian Veluchamy Syncfusion Team May 7, 2019 08:40 AM UTC

Hi Julian, 
Thank you for update. 
We have checked the reported query "Exception is raised when we try to export DataGrid with unbound rows in Xamarin.Forms" and it working as expected from our side. We cannot able to reproduce the issue from our end with the provided information. We have attached the for your reference. 
Please check the sample and let us know if you’re still facing the same issue? If not, please modify the sample based on your scenario and revert us back with replication procedure to replicate the issue along with the following details, 
·       Xamarin.Forms version. 
·       Issue reproducing platform. 
It will be helpful for us to check on it and provide you the solution. 
Subburaj Pandian V 

JU Julian May 7, 2019 08:53 PM UTC

Hi Subburaj Pandian V,

thanks for the sample. I have tested it without doing any changes. That way it works fine.

Then I did some little changes to meet my purposes:

- You will see some changes in the "ExportToPdf"-method from "MainPage" but these are not causing the error.
- You will see some changes in the constructor from "MainPage", because I need the GridUnboundRow created programmatically. This little change results in my mentioned exception!

For more detail take a look at the attached zip-file.

I have not changed the Xamarin.Forms version.
I have tested it under UWP.

Now You should be able to reproduce it. If You still need any further information, feel free to cantact me.



Attachment: ExpprtUnBoundRow1541713638_UPDATED_c28a637b.zip

SP Subburaj Pandian Veluchamy Syncfusion Team May 8, 2019 11:37 AM UTC

Hi Julian, 
Thank you for the update. 
We have checked and we can able to replicate the reported issue “Exception is raised when we try to export DataGrid with unbound rows” in Xamarin.Forms. We have logged issue report for the same, we will fix this issue and include the issue fix in our weekly NuGet update and it will be available on May 28, 2019. We appreciate your patience until then. 
You can also track the status of the report by following feedback link, 
Subburaj Pandian V 

SP Subburaj Pandian Veluchamy Syncfusion Team May 29, 2019 08:59 AM UTC

Hi Julian,  
We have fixed the reported issue “Exception is raised when we try to export DataGrid with unbound rows” and included the issue fix in our weekly NuGet package update version and is available for download (nuget.org). This issue fix will be included in our upcoming 2019 Volume 2 release as well. 
We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you would require any further assistance. 
Subburaj Pandian V 

Live Chat Icon For mobile
Up arrow icon