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

GridControl.ActiveGridView is null

Thread ID:





141019 Nov 19,2018 01:46 PM UTC Nov 21,2018 09:22 AM UTC WinForms 5
Tags: GridControl
Mihaivladut STAN
Asked On November 19, 2018 01:46 PM UTC


I encounter the next error: Object reference not set to an instance of an object. 
The stack trace: 
   at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridCellToExcel(GridModel grid, Int32 iRow, Int32 iColumn, IRange range)
   at Syncfusion.GridExcelConverter.GridExcelConverterControl.GridToExcel(GridModel grid, IWorksheet sheet, ConverterOptions options)

After investigations, I've saw that ActiveGridView property is null.
We construct the model for exporting in the next way:
            GridControl gridValues;
            var s = new MemoryStream();      
            gridValues.SaveBinary(s); // public void SaveBinary(Stream s); => Assembly Syncfusion.Grid.Windows, Version=16.2451.0.41
            s.Seek(0, SeekOrigin.Begin);
            var gridTemp = new CustomGridControl(GridModel.LoadBinary(s)); // public class CustomGridControl : Syncfusion.Windows.Forms.Grid.GridControl
// gridTemp.ActiveGridView  is null after this step and crashes the excel export.
... => some transformations/aggregations and return gridTemp 

As a mention, the ActiveGridView have the next attribute: [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] .
I have changed the version of libraries some time ago, and right now i have all syncfusion dll's at version 16.2451.0.41 .

Can you please tell me how to proceed and set properly this property ?

Have a good day,

Arulraj A [Syncfusion]
Replied On November 20, 2018 06:49 AM UTC

Hi Mihaivladut, 

Thanks for using Syncfusion product. 

We can reproduce your reported scenario. By default, GridControl.ActiveGridView initialized when you add the GridControl inside any control to display. So, If you want to export the custom grid without displaying, you could add that control inside of any control to initialize the ActiveGridView. Please refer the following code example, 

Panel p = new Panel(); 
var s = new MemoryStream(); 
s.Seek(0, SeekOrigin.Begin); 
var grid = new CustomGrid(GridModel.LoadBinary(s)); 

Let us know whether this helps also if you need any further assistance on this. 

Arulraj A 

Mihaivladut STAN
Replied On November 20, 2018 10:05 AM UTC

Hello Arulraj,

Thank you for your promptitude.
Your indication and sample are very helpful, however i need to add headers to the excel export.

My application has a syncfusion grid with nested headers. I would like to know how to export the headers to excel. Please  see the attachment.

In the first sheet, is how i would like to be my export. With your code is almost good(without headers).
In the second sheet, i adapted your sample with desired headers.

Have a good day,

Mihaivladut STAN
Replied On November 20, 2018 10:10 AM UTC

And the attachment.

Attachment: export_sample_6f7f9574.zip

Arulraj A [Syncfusion]
Replied On November 21, 2018 06:38 AM UTC

Hi Mihai, 

Thanks for your update. 

To export the grid with headers, you could use the ConverterOptions.ColumnHeaders option. Please refer the below code example and the UG link, 

//Converter to export the contents of the Grid to Excel. 
GridExcelConverterControl excelConverter = new GridExcelConverterControl(); 
//Set converter options to export the Grid with Row Headers and Column Headers 
excelConverter.GridToExcel(this.gridControl1.Model, "SampleExcel.xlsx", ConverterOptions.ColumnHeaders | ConverterOptions.RowHeaders); 

Let us know whether this helps also if you need any further assistance on this. 

Arulraj A 

Mihaivladut STAN
Replied On November 21, 2018 09:22 AM UTC

Hi Arulraj,
Thank you for your help.

I wish you all the best,


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon