Save DataGridView to XML

Jan 6 2010 4:41 AM
Hello All
This issue has got to do with saving and retrieving data from xml into DataGridViews and vice versa
My xml file would look like this
 
<?xml version="1.0" encoding="utf8" ?>
 <TestDescription xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" DeviceName="Three phase meter1" DeviceType="DeltaPlus1" DescriptionId="79AB314238CD423dA0CB4D49D3E75F13" Status="NotStarted" Version="1.0" TimeStamp="20021010T02:00:00+05:30" xmlns="urn:DeviceTestDescription">
 <CommunicationDescription>
<PhysicalMedia>RS232</PhysicalMedia>
<CommunicationProtocol>Modbus</CommunicationProtocol>
<DeviceAddress>1</DeviceAddress>
<CommunicationPort>1</CommunicationPort>
<BaudRate>4800</BaudRate>
<HandShake>XON</HandShake>
</CommunicationDescription>
 <TestSuite>
 <TestGroup ID="1001" Description="Group1" ErrorCondition="Skip">
 <TestCase ID="1001" Description="CT">
 <TestStep Command="SetCT" ID="" Description="Set CT">
 <Parameters>
<Parameter Name="setCTRatio" Value="8232" Direction="Write" />
</Parameters>
</TestStep>
 <TestStep Command="ReadCT" ID="" Description="Get CT">
 <Parameters>
<Parameter Name="getCTRatio" Direction="Read" />
</Parameters>
</TestStep>
<ValidationCriteria>if setCTRatio == getCTRatio testResult.valid = true else testResult.valid = false end</ValidationCriteria>
<ValidationError />
</TestCase>
</TestGroup>
</TestSuite>
<Log>Test Executed by : User1 Test Type : FTTPOC Remarks : DEMO version. Usage permitted for demonstration purposes only.</Log>
</TestDescription>
 
As you see above there are sections for Descriptions , CommunicationDescription, TestSteps and TestParamters
For each of the above sections i have a separate data grid view  and a separate dataset (ds , ds1, ds2, ds3) in my app. I am able to populate the data grid views properly but i am unable to save the modified datagridview into xml . How should i do this ? And since the data is spread over many data grid views , this is more confusing coz i have many data sets each pertaining to one datagridview.
I made a few changes to the "communicationDescription" and used  "ds1.AcceptChanges() ". It did not save . Using WriteXML () did save but the file got completely erased . Check my code .. Dont think it is any where close to correct
 
if (ds1.HasChanges() || ds2.HasChanges() || ds3.HasChanges() || ds.HasChanges())
{
DescriptionMode mode = (DescriptionMode)Enum.Parse(typeof(DescriptionMode), CurrentNavigation);
string[] files = Directory.GetFiles("D:\\TFS\\Code Snippets\\TestController\\TestController\\bin\\Debug\\" + mode.ToString(), "*.xml");
String file = files[overviewClickedRowIndex];
ds1.WriteXml(file);
ds2.WriteXml(file);
ds3.WriteXml(file);
ds.WriteXml(file);
}

Any help will be greatly appreciated. Thanks! Please respond asap..
AVink

Answers (6)