Adding row to existing repeating table in C# - InfoPath Dev
in

InfoPath Dev

Adding row to existing repeating table in C#

Last post 06-12-2012 07:03 AM by PaulRAnderson. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-11-2012 01:28 PM

    Adding row to existing repeating table in C#

    I want my form to store data about imported XML files in a repeating table. New information should go in a new row, but my code always replaces the existing row with the new data.

    The schema is

         SAN (root)
         |-- my:ConstantVariables (group)
             |-- my:LassoCollections (group)
                 |-- my:LassoCollection (repeating group)
                     |-- my:LassoFileName
                     |-- my:LassoBuildVersion

    The data I want to store in LassoFileName and LassoBuildVersion is stored in strLassoXMLFile and strLassoXMLVersion.

    The new XmlDocument "doc" I am making contains the following XML when the code is run:

         <my:LassoCollection xmlns:my=
    "http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-03-16T10:53:27">
             <my:LassoFileName>Lasso_Northern_Lakes_Colle_Collect_Output_20120420_115048_GMT-700.xml</my:LassoFileName>
             <my:LassoBuildVersion>4.1</my:LassoBuildVersion>
         </my:LassoCollection>

    This looks correct to me.

    Here is the code that doesn't work:

       XmlDocument doc = new XmlDocument();
       XmlNode group = doc.CreateElement("my:LassoCollection", NamespaceManager.LookupNamespace("my"));

       XmlNode fileField = doc.CreateElement("my:LassoFileName", NamespaceManager.LookupNamespace("my"));
       XmlNode fileNode = group.AppendChild(fileField);
       fileNode.InnerText = strLassoXMLFile;

       XmlNode versionField = doc.CreateElement("my:LassoBuildVersion", NamespaceManager.LookupNamespace("my"));
       XmlNode versionNode = group.AppendChild(versionField);
       versionNode.InnerText = strLassoXMLVersion;

       doc.AppendChild(group);
       MainDataSource.CreateNavigator().SelectSingleNode("/SAN/my:ConstantVariables/my:LassoCollections", NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

    What am I doing wrong here?

    Paul

  • 06-12-2012 07:03 AM In reply to

    Re: Adding row to existing repeating table in C#

    I've discovered my problem.  My code left an empty row at the beginning.  Once I deleted that empty row, future AppendChild operations added a new row at the bottom.

    Paul

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.