ARACK04
asked on
System.InvalidOperationException: reentrant call to SetCurrentCellAddressCore
I have a datagridview which is bound to a List of business objects. I am catching the CellEndEdit event, and calling the update method in my O/R Mapper. When I edit a cell and hit enter, it works fine.
Unfortunately, when I edit a cell, and then click on a different cell, I get this error:
System.InvalidOperationExc eption: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.
This absolutely has me stumped, and any help would be much appreciated.
Unfortunately, when I edit a cell, and then click on a different cell, I get this error:
System.InvalidOperationExc
This absolutely has me stumped, and any help would be much appreciated.
ASKER
Is there any way I can cancel the cell click event before it goes through all that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That's ok - thanks!
ASKER
looks like the BindindSource works perfectly - I didn't really need help setting it up, I just didn't want to change my application.
great!
ASKER
One quick thing - if I'm catching the listchanged event, is it then possible to have the datagridView enter edit mode, on a specific cell? I tried the following, but it's not working (not doing anything)
void BS_ListChanged(object sender, ListChangedEventArgs e) {
bind();
dataGridView1.CurrentCell = dataGridView1.Rows[2].Cell s[2];
dataGridView1.BeginEdit(fa lse);
}
void BS_ListChanged(object sender, ListChangedEventArgs e) {
bind();
dataGridView1.CurrentCell = dataGridView1.Rows[2].Cell
dataGridView1.BeginEdit(fa
}
It doesn't work because later in the process the currentcell of the datagridview is changed elsewhere, thus overriding your code.
You need to put this code in an event that happens after the datagrid update process has finished. e.g. you could put it in the validated event of the datagridview.
This is what happens when you click a cell in the datagrid:
setcurrentcell -> cellendedit -> (your event handler) -> setcurrentcell
my suggestion: Use a BindingSource when binding your business objects to the datagrid and listen for the listchanged event of the BindingSource object instead of the CellEndEdit event.