Runtime error in PivotGridControl data binding [Solved]
-
Hi, I'm trying to use Devexpress library in my own project. I use PivotGridControl to load an excel data into PivotTable. For a test, I used the following code:
public Form1()
{
ExcelDataSource myExcelSource = new ExcelDataSource();
myExcelSource.FileName = @"C:\Users\Fardin\Desktop\Book1.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("Sheet1", "A1:B20");
myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
myExcelSource.SourceOptions.SkipEmptyRows = false;
myExcelSource.SourceOptions.UseFirstRowAsHeader = true;
myExcelSource.Fill();
pivotGridControl1.DataSource = myExcelSource;
}But there is following error in
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I upload the whole project package: https://www.dropbox.com/s/vmokcgu21jqohpo/DXApplication1.rar?dl=0 And for Excel file: Dropbox - Book1.xlsx - Simplify your life[^] Please guide me.
-
Hi, I'm trying to use Devexpress library in my own project. I use PivotGridControl to load an excel data into PivotTable. For a test, I used the following code:
public Form1()
{
ExcelDataSource myExcelSource = new ExcelDataSource();
myExcelSource.FileName = @"C:\Users\Fardin\Desktop\Book1.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("Sheet1", "A1:B20");
myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
myExcelSource.SourceOptions.SkipEmptyRows = false;
myExcelSource.SourceOptions.UseFirstRowAsHeader = true;
myExcelSource.Fill();
pivotGridControl1.DataSource = myExcelSource;
}But there is following error in
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I upload the whole project package: https://www.dropbox.com/s/vmokcgu21jqohpo/DXApplication1.rar?dl=0 And for Excel file: Dropbox - Book1.xlsx - Simplify your life[^] Please guide me.
-
Hi, I'm trying to use Devexpress library in my own project. I use PivotGridControl to load an excel data into PivotTable. For a test, I used the following code:
public Form1()
{
ExcelDataSource myExcelSource = new ExcelDataSource();
myExcelSource.FileName = @"C:\Users\Fardin\Desktop\Book1.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("Sheet1", "A1:B20");
myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
myExcelSource.SourceOptions.SkipEmptyRows = false;
myExcelSource.SourceOptions.UseFirstRowAsHeader = true;
myExcelSource.Fill();
pivotGridControl1.DataSource = myExcelSource;
}But there is following error in
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I upload the whole project package: https://www.dropbox.com/s/vmokcgu21jqohpo/DXApplication1.rar?dl=0 And for Excel file: Dropbox - Book1.xlsx - Simplify your life[^] Please guide me.
Impossible to answer properly, since you didn't even tell us which line / variable is
null
. At a guess, thepivotGridControl1
is initialized in the compiler-generatedInitializeComponent
method, which you haven't called. Therefore, the field isnull
, and you get aNullReferenceException
on thepivotGridControl1.DataSource = myExcelSource;
line.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Hi, I'm trying to use Devexpress library in my own project. I use PivotGridControl to load an excel data into PivotTable. For a test, I used the following code:
public Form1()
{
ExcelDataSource myExcelSource = new ExcelDataSource();
myExcelSource.FileName = @"C:\Users\Fardin\Desktop\Book1.xlsx";
ExcelWorksheetSettings worksheetSettings = new ExcelWorksheetSettings("Sheet1", "A1:B20");
myExcelSource.SourceOptions = new ExcelSourceOptions(worksheetSettings);
myExcelSource.SourceOptions.SkipEmptyRows = false;
myExcelSource.SourceOptions.UseFirstRowAsHeader = true;
myExcelSource.Fill();
pivotGridControl1.DataSource = myExcelSource;
}But there is following error in
System.NullReferenceException: 'Object reference not set to an instance of an object.'
I upload the whole project package: https://www.dropbox.com/s/vmokcgu21jqohpo/DXApplication1.rar?dl=0 And for Excel file: Dropbox - Book1.xlsx - Simplify your life[^] Please guide me.
Just to add to what Richard has said... When you create a form, all the "heavy lifting" of creating controls, setting form properties, and suchlike is performed for you in the
MyFile.Designer.cs
file methodInitializeComponent
, which is why the default Form file always contains a constructor which calls it as the first line of code. This file is created and maintained by the VS designer and isn't normally edited directly. If you don't callInitializeComponent
when you edit the Form constructor, then no controls or properties are ever created for you, and the variables allocated by the designed for them will remain empty - they will contain the default value for a reference value:null
So when your code tries to use them for anything at all, you will get a null reference error, as you have seen. To be honest, you should have spotted that yourself, and thirty seconds with the debugger would have put you on the right track pretty much immediately! It's worth getting used to the debugger, it's your best friend and will save you hours of hair pulling frustration!"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
-
Just to add to what Richard has said... When you create a form, all the "heavy lifting" of creating controls, setting form properties, and suchlike is performed for you in the
MyFile.Designer.cs
file methodInitializeComponent
, which is why the default Form file always contains a constructor which calls it as the first line of code. This file is created and maintained by the VS designer and isn't normally edited directly. If you don't callInitializeComponent
when you edit the Form constructor, then no controls or properties are ever created for you, and the variables allocated by the designed for them will remain empty - they will contain the default value for a reference value:null
So when your code tries to use them for anything at all, you will get a null reference error, as you have seen. To be honest, you should have spotted that yourself, and thirty seconds with the debugger would have put you on the right track pretty much immediately! It's worth getting used to the debugger, it's your best friend and will save you hours of hair pulling frustration!"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!
Thanks. I saw in debugger that says "
pivotGridControl1 was null.
but I didn't know what was wrong with it. Now, I can run the component but my Excel data isn't listed in the PivotGridControl and still says drop filter items.
-
Thanks. I saw in debugger that says "
pivotGridControl1 was null.
but I didn't know what was wrong with it. Now, I can run the component but my Excel data isn't listed in the PivotGridControl and still says drop filter items.
I solved it:
pivotGridControl1.RetrieveFields();
-
I solved it:
pivotGridControl1.RetrieveFields();
:-D
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!