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. DataGridView InvalidOperationException re-entrancy issue when setting its DataSource to null

DataGridView InvalidOperationException re-entrancy issue when setting its DataSource to null

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 3 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.
  • C Offline
    C Offline
    Cyrilix
    wrote on last edited by
    #1

    I'm getting an InvalidOperationException with the following message: "Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function." Essentially, the context is this: Initially, I do something like this:

    BindingSource bds = new BindingSource(dataSet1, dataTableString1);
    dataGridView1.DataSource = bds;

    But, say I perform an operation on the datagrid which makes me want to reload the entire datagrid. What I do is something like this:

    dataGridView1.DataSource = null;
    dataGridView1.DataBindings.Clear();
    dataSet1.Clear();

    //Retrieve data from the SqlAdapter and re-bind the datagridview
    sqlDataAdapter1.Fill(dataSet1);
    BindingSource bds = new BindingSource(dataSet1, dataTableString1);
    dataGridView1.DataSource = bds;

    The exception is thrown on the first statement when the data source is set to null. I've looked around and it seems like various situations will cause this issue, but not enough to give me a good idea on how to fix it.

    L S 2 Replies Last reply
    0
    • C Cyrilix

      I'm getting an InvalidOperationException with the following message: "Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function." Essentially, the context is this: Initially, I do something like this:

      BindingSource bds = new BindingSource(dataSet1, dataTableString1);
      dataGridView1.DataSource = bds;

      But, say I perform an operation on the datagrid which makes me want to reload the entire datagrid. What I do is something like this:

      dataGridView1.DataSource = null;
      dataGridView1.DataBindings.Clear();
      dataSet1.Clear();

      //Retrieve data from the SqlAdapter and re-bind the datagridview
      sqlDataAdapter1.Fill(dataSet1);
      BindingSource bds = new BindingSource(dataSet1, dataTableString1);
      dataGridView1.DataSource = bds;

      The exception is thrown on the first statement when the data source is set to null. I've looked around and it seems like various situations will cause this issue, but not enough to give me a good idea on how to fix it.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Cyrilix wrote:

      dataGridView1.DataSource = bds;

      That should be sufficient to replace the datasource.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4 out now (27 May 2008)

      C 1 Reply Last reply
      0
      • L leppie

        Cyrilix wrote:

        dataGridView1.DataSource = bds;

        That should be sufficient to replace the datasource.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 4 out now (27 May 2008)

        C Offline
        C Offline
        Cyrilix
        wrote on last edited by
        #3

        I will give that a try. Thanks.

        L 1 Reply Last reply
        0
        • C Cyrilix

          I will give that a try. Thanks.

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          You maybe have to 'reset' your bindings on the bindingsource if I remember correctly. But you should never have to clear it AFAIK :)

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4 out now (27 May 2008)

          1 Reply Last reply
          0
          • C Cyrilix

            I'm getting an InvalidOperationException with the following message: "Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function." Essentially, the context is this: Initially, I do something like this:

            BindingSource bds = new BindingSource(dataSet1, dataTableString1);
            dataGridView1.DataSource = bds;

            But, say I perform an operation on the datagrid which makes me want to reload the entire datagrid. What I do is something like this:

            dataGridView1.DataSource = null;
            dataGridView1.DataBindings.Clear();
            dataSet1.Clear();

            //Retrieve data from the SqlAdapter and re-bind the datagridview
            sqlDataAdapter1.Fill(dataSet1);
            BindingSource bds = new BindingSource(dataSet1, dataTableString1);
            dataGridView1.DataSource = bds;

            The exception is thrown on the first statement when the data source is set to null. I've looked around and it seems like various situations will cause this issue, but not enough to give me a good idea on how to fix it.

            S Offline
            S Offline
            sanme98
            wrote on last edited by
            #5

            I also encounter the same problem, anyone here have solution for this problem?

            C 1 Reply Last reply
            0
            • S sanme98

              I also encounter the same problem, anyone here have solution for this problem?

              C Offline
              C Offline
              Cyrilix
              wrote on last edited by
              #6

              Whoa, this thread is old. Well, I ended up changing a lot of code during all of this, and never really got down to the bottom of the problem, so I scrapped the idea. Essentially, I was trying to change a DataGrid into a DataGridView, although there was probably other existing code and assumptions I wasn't aware of, that caused this problem. Sorry I couldn't be of more use.

              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