Dynamically Copying InfoPath Field Data using XML Object Model - InfoPath Dev
in

InfoPath Dev

Dynamically Copying InfoPath Field Data using XML Object Model

Last post 04-20-2011 05:13 AM by Skarn. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-30-2011 07:40 AM

    Dynamically Copying InfoPath Field Data using XML Object Model

    Hello All,
    I currently have a situation in which I need to dynamically populate a new row in a repeating table on an InfoPath form. I currently have three fields in a repeating table (field1, field2, field3). I also have a button that says Add Row. The code behind the button dynamically creates/appends a new field onto each previous field when the button is clicked and populates the text (Cell 1, Cell2, Cell3) respectfully. I also have a fourth text field on the form, outside of the repeating table called field4. Instead of populating standard text into fields 1,2,3, I wish to be able to copy the text/value entered in field4 into the field(s) inside the repeating table. It sounds easy but I have found it extremely difficult to understand each class and its methods for the XML object model. Could someone please take a look at the code below and perhaps show me the code to do just that. The code below is placed on the Add Row button clicked event. Any help would be wonderful. Thanks

    XmlDocument doc = new XmlDocument();
    XmlNode group = doc.CreateElement("group2", NamespaceManager.LookupNamespace("my"));
    XmlNode field = doc.CreateElement("field1", NamespaceManager.LookupNamespace("my"));
    XmlNode node = group.AppendChild(field);
    node.InnerText ="Cell 1";  //<--------Instead of text here I would like the value from field4. This would require creating an instance of field4 and I am unsure of the syntax----------->
    field = doc.CreateElement("field2", NamespaceManager.LookupNamespace("my"));
    node = group.AppendChild(field);
    node.InnerText ="Cell 2";
    field = doc.CreateElement("field3", NamespaceManager.LookupNamespace("my"));
    node = group.AppendChild(field);
    node.InnerText ="Cell 3";
    doc.AppendChild(group);
    MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group1", NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

     

  • 04-20-2011 05:13 AM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Re: Dynamically Copying InfoPath Field Data using XML Object Model

     On repeating tables in the properties window you could use Default Values or 'rules when user adds/inserts a row' and set each field to the value in your field outside the table. No code needed.

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