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.
Unfortunately, activation email could not send to your email. Please try again.

I cant print grid.

Thread ID:

Created:

Updated:

Platform:

Replies:

125661 Aug 31,2016 11:55 AM Sep 1,2016 08:52 AM UWP 1
loading
Tags: SfDataGrid
Andrew Overlord
Asked On August 31, 2016 11:55 AM

When i try to print my grid i have this error: "Value cannot be null."

This is my code:
            SfDataGrid dataGrid = new SfDataGrid();
            dataGrid.Columns.Add(new GridTextColumn() { HeaderText = "Order ID", MappingName = "OrderID" });
            dataGrid.Columns.Add(new GridTextColumn() { HeaderText = "Customer ID", MappingName = "CustomerID" });
            dataGrid.Columns.Add(new GridTextColumn() { HeaderText = "Customer Name", MappingName = "CustomerName" });
            dataGrid.Columns.Add(new GridTextColumn() { HeaderText = "Country", MappingName = "Country" });
            dataGrid.Columns.Add(new GridNumericColumn() { HeaderText = "Unit Price", MappingName = "UnitPrice" });
            dataGrid.PrintSettings = new PrintSettings();
            dataGrid.PrintSettings.PrintPageOrientation = PrintOrientation.Portrait;
            dataGrid.Print();


Jai Ganesh S [Syncfusion]
Replied On September 1, 2016 08:52 AM

Hi Andrew,

Thanks for contacting Syncfusion Support.

In SfDataGrid  it is not possible to perform the Print operation without creating the SfDataGrid.View. But you can achieve your requirement “printing a SfDataGrid from code behind” by using the below code example, Here we have created the SfDataGrid.View manually.

C# 

SfDataGrid grid = new SfDataGrid(); 
            grid.ItemsSource = (new OrderInfoViewModel()).OrdersListDetails; 
 
            GridQueryableCollectionViewWrapper wrapper = new GridQueryableCollectionViewWrapper((this.DataContext as OrderInfoViewModel).OrdersListDetails, grid); 
            grid.ItemsSource = wrapper; 
            grid.Columns.Add(new GridTextColumn() { MappingName = "CustomerID" }); 
            grid.Columns.Add(new GridTextColumn() { MappingName = "Discount" }); 
 
            grid.PrintSettings = new PrintSettings(); 
            grid.PrintSettings.PrintManagerBase = new PrintManagerBase(wrapper); 
            grid.PrintSettings.PrintPageOrientation = PrintOrientation.Portrait; 
            grid.PrintSettings.PrintManagerBase.Print();

 

We have prepared a sample as per your requirement and you can download the sample from the below location,

Sample :  

Regards,  
Jai Ganesh S 




CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;