Infopath 2007 - Copy Repeating Table Data into another Repeating Table Programmatically - InfoPath Dev
in

InfoPath Dev

Infopath 2007 - Copy Repeating Table Data into another Repeating Table Programmatically

Last post 11-10-2010 10:38 PM by ciaramc. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 11-09-2010 09:55 PM

    Infopath 2007 - Copy Repeating Table Data into another Repeating Table Programmatically

    Hi,

    I have a repeating table in my InfoPath form where users fill out data. When they click a button I want to populate a different repeating table within the same form (using only some columns but all rows)

    Im using C# code (below) to do this (wont have Qdabra for the near future) and at the moment Im getting no results - when the user clicks the button nothing happens. 

    The populated table = /my:Sect_Main/my:RequestDetails/my:Products/my:Product

    The table I want to populate =/my:Sect_Main/my:RequestDetails/my:Sect_Retailers/my:RetailerProducts

    -------------------------------------------------------
       XPathNavigator rootMain = MainDataSource.CreateNavigator().SelectSingleNode("/my:Sect_Main/my:RequestDetails/my:Products/my:Product", NamespaceManager);
    XPathNavigator rootSecondary = MainDataSource.CreateNavigator().SelectSingleNode("/my:Sect_Main/my:RequestDetails/my:Sect_Retailers/my:RetailerProducts", NamespaceManager);

    // Select nodes in specified XPathNavigator.

    XPathNodeIterator selectedNodes = rootSecondary.Select("/my:Sect_Main/my:RequestDetails/my:Sect_Retailers/my:RetailerProducts", NamespaceManager);

    XmlWriter writer = rootMain.SelectSingleNode("/my:Sect_Main/my:RequestDetails/my:Products/my:Product", NamespaceManager).AppendChild();

    string myNamespace = NamespaceManager.LookupNamespace("my");

    foreach (XPathNavigator node in selectedNodes)
    {
    writer.WriteStartElement("Products", myNamespace);
    writer.WriteElementString("Products_ProductName", myNamespace, node.GetAttribute("Retailers_ProductName", ""));
    writer.WriteEndElement();
    }
     ----------------------------------------- 
    Any help would be much appreciated!

     Thanks,

    Ciara

  • 11-10-2010 10:38 PM In reply to

    Re: Infopath 2007 - Copy Repeating Table Data into another Repeating Table Programmatically

     Managed to get it working with this code if anybody is interested - Table 1 is being copied into Table 2

     

                 string myNamespace = NamespaceManager.LookupNamespace("my");

                XPathNodeIterator xIter = MainDataSource.CreateNavigator().Select("/my:myFields/my:Table1/my:rpt_Table1", NamespaceManager);

                //while (xIter.MoveNext())
                foreach (XPathNavigator node in xIter)
                {
                    using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Table2", NamespaceManager).AppendChild())
                    {
                        writer.WriteStartElement("rpt_Table2", myNamespace);
                        writer.WriteElementString("fieldB1", myNamespace, node.SelectSingleNode("my:fieldA1", NamespaceManager).Value);
                        writer.WriteElementString("fieldB2", myNamespace, node.SelectSingleNode("my:fieldA2", NamespaceManager).Value);
                        writer.WriteEndElement();
                        writer.Close();
                    }
                }
                //Remove 1st row [It's empty by default]
                XPathNavigator FirstRowNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Table2/my:rpt_Table2", NamespaceManager);
                FirstRowNode.DeleteSelf();

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