Datagrid: Stop/Cancel the AddNew or the EditItem Transaction?

1.1k views Asked by At

I use a datagrid to show coordinates of "selection rectangles" that the user can create on an image.

I use databinding of the data grid to an observable collection, since the coordinates are also needed for other purposes.

So, when the user creates a new Rectangle, an new entry is added to the Observable collection.

To directly display the coordinates of the new rectangle in the datagrid i have to call "myDatagrid.Items.Refresh()".

The problem is now, that in some cases, the program fails with an "Invalid Operation Exception", that says the Refresh() can not be done "while an AddNew or EditItem - Transaction" on the datagrid is running.

I don't know exactly, where this Transactions are triggered, but i observes that the exception only occurs, when the Mouse-Courser was active in one cell of the datagrid at the moment, when the Refresh() is called.

So there would be some possible hints that would really help me:

  • How can I 'manually' cancel the Edit-Mode for all cells of the datagrid? (of course I have tried the DataGrid.CancelEdit() and DataGrid.CommitEdit(), but that doesn't help)
  • What is an EditItem-Transaction / AddItem-Transaction or how can I stop it running?
  • Any other ideas to safely update the binding without using DataGrid.Refresh()..
0

There are 0 answers