I have some XML data in the form
<GPSettings>
<ProductCount>3</ProductCount>
<MainDelimiter>:</MainDelimiter>
<SubDelimiter>space</SubDelimiter>
<GPProducts>
<GPProduct>
<ProductName>myProduct1</ProductName>
<ProductCode>1234</ProductCode>
<ConfigurationCount>2</ConfigurationCount>
<Current>1</Current>
<GPConfigurations>
<GPConfiguration>
<ConfigurationName>myConfigProd1</ConfigurationName>
<PairCount>7</PairCount>
<CustomPairCount>1</CustomPairCount>
<GPPairs>
<GPPair>
<Name>Width1</Name>
<ResultString>m_Width1</ResultString>
<DefaultValue>15</DefaultValue>
<UseDefault>false</UseDefault>
<IncludeInString>true</IncludeInString>
<Comment>This is Width 1</Comment>
<Order>7</Order>
</GPPair>
<GPair>
<Name>Width2</Name>
<ResultString>m_Width2</ResultString>
<DefaultValue>100</DefaultValue>
<UseDefault>true</UseDefault>
<IncludeInString>true</IncludeInString>
<Comment>This is Width 2</Comment>
<Order>2</Order>
</GPPair>
I deserialize into my classes set up as below:
[Serializable()]
[XmlRoot("Settings")]
public class Settings
{
[XmlElement("ProductCount")]
public int ProductCount{ get; set; }
[XmlElement("MainDelimiter")]
public string MainDelimiter { get; set; }
[XmlElement("SubDelimiter")]
public string SubDelimiter { get; set; }
[XmlArray("GPProducts")]
[XmlArrayItem("GPProduct", typeof(GPProduct))]
public GPProduct[] GPProduct { get; set; }
[Serializable()]
public class GPProduct
{
[XmlElement("ProductName")]
public string ProductName { get; set; }
[XmlElement("ProductCode")]
public string ProductCode { get; set; }
[XmlElement("ConfigurationCount")]
public int ConfigurationCount { get; set; }
[XmlElement("Current")]
public int Current { get; set; }
[XmlArray("GPConfigurations")]
[XmlArrayItem("GPConfiguration", typeof(GPConfiguration))]
public GPConfiguration[] GPConfiguration { get; set; }
[Serializable()]
public class GPConfiguration
{
[XmlElement("ConfigurationName")]
public string ConfigurationName { get; set; }
[XmlElement("PairCount")]
public int PairCount { get; set; }
[XmlElement("CustomPairCount")]
public int CustomPairCount { get; set; }
[XmlArray("GPPairs")]
[XmlArrayItem("GPPair", typeof(GPPair))]
public GPPair[] GPPair { get; set; }
[Serializable]
public class GPPair : IComparable
{
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("ResultString")]
public string ResultString { get; set; }
[XmlElement("DefaultValue")]
public string DefaultValue { get; set; }
[XmlElement("UseDefault")]
public bool UseDefault { get; set; }
[XmlElement("IncludeInString")]
public bool IncludeInString { get; set; }
[XmlElement("Comment")]
public string Comment { get; set; }
[XmlElement("Order")]
public int Order { get; set; }
Deserialization with:
string path = @"C:\test.xml";
XmlSerializer serializer = new XmlSerializer(typeof(GPSettings));
StreamReader reader = new StreamReader(path);
GPSettings = (GPSettings)serializer.Deserialize(reader);
reader.Close();
The main form contains two combo boxes which allow for selection of the GPProduct and the GPConfigurations, and then the GPPair values are all displayed in a datagridview.
I want to be able to add a row to this datagridview and have the underlying object updated for serialization later. I can find no good way to get this done, any ideas?
Thanks