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