T
Troy McLure
I have loaded some xml into a dataset, created a XmlDataDocument of it
and displayed the data in a DatagridView. When I do an
XmlNode.RemoveChild, I get "System.Data.RowNotInTableException: This row
has been removed from a table and does not have any data." How can I
avoid this exception? (I must be able to manipulate the XML and see
changes in DataGridView automatically.)
The xml:
<?xml version="1.0" encoding="utf-8"?>
<webmapproject xmlns="http://tempuri.org/webmapproject.xsd">
<legs>
<legendentry>
<leindex>0</leindex>
<title>Title 0</title>
</legendentry>
<legendentry>
<leindex>100</leindex>
<title>Title 1</title>
</legendentry>
<legendentry>
<leindex>200</leindex>
<title>Title 2</title>
</legendentry>
<legendentry>
<leindex>300</leindex>
<title>Title 3</title>
</legendentry>
</legs>
</webmapproject>
The code:
System.Xml.XmlDataDocument gXmlDoc;
System.Windows.Forms.DataGridView dataGrid1;
DataSet ds = new DataSet();
string xmlFile = Application.StartupPath + "\\..\\..\\proj.xml";
ds.ReadXml(xmlFile);
ds.EnforceConstraints=false;
gXmlDoc = new System.Xml.XmlDataDocument(ds);
this.dataGrid1.DataMember = "legendentry";
this.dataGrid1.DataSource = ds;
//trying to delete the first row (the first legendentry node):
XmlNode nFirst = gXmlDoc.DocumentElement.FirstChild.FirstChild;
nFirst.ParentNode.RemoveChild(nFirst); //fails
and displayed the data in a DatagridView. When I do an
XmlNode.RemoveChild, I get "System.Data.RowNotInTableException: This row
has been removed from a table and does not have any data." How can I
avoid this exception? (I must be able to manipulate the XML and see
changes in DataGridView automatically.)
The xml:
<?xml version="1.0" encoding="utf-8"?>
<webmapproject xmlns="http://tempuri.org/webmapproject.xsd">
<legs>
<legendentry>
<leindex>0</leindex>
<title>Title 0</title>
</legendentry>
<legendentry>
<leindex>100</leindex>
<title>Title 1</title>
</legendentry>
<legendentry>
<leindex>200</leindex>
<title>Title 2</title>
</legendentry>
<legendentry>
<leindex>300</leindex>
<title>Title 3</title>
</legendentry>
</legs>
</webmapproject>
The code:
System.Xml.XmlDataDocument gXmlDoc;
System.Windows.Forms.DataGridView dataGrid1;
DataSet ds = new DataSet();
string xmlFile = Application.StartupPath + "\\..\\..\\proj.xml";
ds.ReadXml(xmlFile);
ds.EnforceConstraints=false;
gXmlDoc = new System.Xml.XmlDataDocument(ds);
this.dataGrid1.DataMember = "legendentry";
this.dataGrid1.DataSource = ds;
//trying to delete the first row (the first legendentry node):
XmlNode nFirst = gXmlDoc.DocumentElement.FirstChild.FirstChild;
nFirst.ParentNode.RemoveChild(nFirst); //fails