DataRowNotInTableException, DataGridView and XmDataDocument

  • Thread starter Thread starter Louis-Pierre Beaumont
  • Start date Start date
L

Louis-Pierre Beaumont

Hello!

I have an XML file that i display and edit into a DataGridView
using a schema, the classes generated from it and
XmlDataDocument.

Here comes the problem: I delete a row in the DataGridView
by pressing the "delete" keyboard key. The DataGridView fires
a RowsRemoved event that I use to save back my XML document.
I do use the WriteXml method of my schema generated class for this purpose.

But it always throws a DataRowNotInTableException. It throws it when i call
WriteXml, AcceptChanges and so on. I looked at the DataRow RowState, and
those
i did delete are in the "Detached" RowState. The DataSet.Remove method also
puts the rows in a "Detached" RowState.

How can i "really remove" the deleted rows so that i can save my XML without
getting
that annoying exception? Please help! : )


Louis-Pierre Beaumont
Software Developer
Labcal Technologies
 
Well, i found out that i must call AccepChanges after loading the data,
then call AccepChanges after deletion, then save. It solved my problem.
The RowStates are now "Deleted" instead of "Detached".
 
Back
Top