Today i was attempting (for the first time) to make a simple application that will allow me to read XML file into Grid View control (via DataSet), and later on save back any changes back to xml file (Win forms application).
For time being i'm "ignoring" the "save" part, as i'm not able even to get the "view/load" part to work proerply, so i will try to get that working later on once i fix the initial problem i'm seeking help for.
I've tried something thats throwing me exception but since i've never tried binding a dataset to XML i'm probably doing something stupid or missing something...
i've made simple xml file (named it: XMLFile1.xml) with the following content:
<br /><?xml version="1.0" encoding="utf-8" ?><br /><item_list><br /> <item><br /> <title>item 1</title><br /> <des>item 1 description</des><br /> </item><br /> <item><br /> <title>item 2</title><br /> <des>item 2 description</des><br /> </item><br /></item_list> <br />
on the form i added:
1. button with default name of button1.
2. DataGridView with default name of dataGridView1.
3. DataSet with default name of dataSet1.
inside the data grid i've created 2 columns with names "title" & "des".
finally created click event for button with the following:
<br /> private void button1_Click(object sender, EventArgs e)<br /> {<br /> string xmlPath = @"..\..\XMLFile1.xml";<br /><br /> dataSet1.ReadXml( xmlPath, XmlReadMode.ReadSchema );<br /> dataGridView1.DataMember = "item";<br /> }<br />
Now the problem i have is the line:
dataGridView1.DataMember = "item";
is thowing exception of "Child list for field item cannot be created".
The truth is i'm not sure if this error is result of invalid xml file i've created, or i'm not using properly the DataMember property.
I would appreciate if anyone could help me & point me in right direction of what i'm doing wrong here.
best regards,
Idan B.