Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Runtime error in PivotGridControl data binding [Solved]

Runtime error in PivotGridControl data binding [Solved]

Scheduled Pinned Locked Moved C#
wpfwcfcomhelptutorial
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Dunlop
    wrote on last edited by
    #1

    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.

    L Richard DeemingR OriginalGriffO 3 Replies Last reply
    0
    • A Alex Dunlop

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      [Devexpress Forums]=>

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      1 Reply Last reply
      0
      • A Alex Dunlop

        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.

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        Impossible to answer properly, since you didn't even tell us which line / variable is null. At a guess, the pivotGridControl1 is initialized in the compiler-generated InitializeComponent method, which you haven't called. Therefore, the field is null, and you get a NullReferenceException on the pivotGridControl1.DataSource = myExcelSource; line.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • A Alex Dunlop

          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.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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 method InitializeComponent, 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 call InitializeComponent 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!

          "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

          A 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            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 method InitializeComponent, 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 call InitializeComponent 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!

            A Offline
            A Offline
            Alex Dunlop
            wrote on last edited by
            #5

            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.

            A 1 Reply Last reply
            0
            • A Alex Dunlop

              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.

              A Offline
              A Offline
              Alex Dunlop
              wrote on last edited by
              #6

              I solved it:

              pivotGridControl1.RetrieveFields();

              OriginalGriffO 1 Reply Last reply
              0
              • A Alex Dunlop

                I solved it:

                pivotGridControl1.RetrieveFields();

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                :-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!

                "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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups