Copy LAST row of repeating table? - InfoPath Dev
in

InfoPath Dev

Copy LAST row of repeating table?

Last post 09-19-2011 09:01 AM by jaxkookie. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 02-08-2010 09:47 AM

    Copy LAST row of repeating table?

    Hello and thank you for such a wonderful resource!

    I've cobbled together some code found here that copies the first row of a repeating table and appends it to the bottom of the repeating table when I click a button. The code looks like this:

    -----
    IXMLDOMNode
    row = thisXDocument.DOM.selectSingleNode("//my:repeatingtable");

    string field1 = row.selectSingleNode("my:field1").text;
    string field2 = row.selectSingleNode("my:field2").text;
    string field3 = row.selectSingleNode("my:field3").text;

    row = row.cloneNode(true);

    row.selectSingleNode("my:field1").text = field1;
    row.selectSingleNode(
    "my:field2").text = field2;
    row.selectSingleNode(
    "my:field3").text = field3;

    IXMLDOMNode parent = thisXDocument.DOM.selectSingleNode("/my:myFields");

    parent.appendChild(row);
    -----

     Is there a simple way to modify this code so that the LAST row of the repeating table is copied?

    Thank you,
    Ken

    Filed under: ,
  • 02-08-2010 06:42 PM In reply to

    Re: Copy LAST row of repeating table?

     What happens if you use "//my:repeatingtable[last()]" in that first line?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-08-2010 09:01 PM In reply to

    Re: Copy LAST row of repeating table?

    try this 

                XPathNodeIterator listItemNav = this.MainDataSource.CreateNavigator().Select("my:myFields/my:group1/my:group2", this.NamespaceManager);
                for (int i = 0; i < listItemNav.Count; i++, listItemNav.MoveNext()) ;
                listItemNav.Current.Clone().InsertAfter(listItemNav.Current);

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 02-09-2010 02:18 PM In reply to

    Re: Copy LAST row of repeating table?

    Thank you both for your replies - I really appreciate it! Jimmy's suggestion worked perfectly and now the button is behaving exactly as I had hoped.

     One last question, if I might... I'm using InfoPath 2007 but this code requires C# with InfoPath 2003 compatibility to run correctly. What are the offending items in this code?

     Thanks again,
    Ken

  • 02-09-2010 06:05 PM In reply to

    Re: Copy LAST row of repeating table?

    kcoakley:
    What are the offending items in this code?
     

    Every single one of them, I'm afraid :-)

     The corresponding code for IP 2007 would be:

    XPathNavigator row = MainDataSource.CreateNavigator().SelectSingleNode("//my:repeatingtable[last()]", NamespaceManager);

    // I don't think you need the value getting and setting code,
    // since the values are already in the row being copied


    XPathNavigator
    parent = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields", NamespaceManager);

    parent.AppendChild(row);

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-10-2010 12:27 PM In reply to

    Re: Copy LAST row of repeating table?

     Jimmy - thanks again for your help. Your IP 2007 code worked like a charm as soon as I realized that my repeating table must be the last node in my "parent" node.

    Thanks again,
    Ken

  • 09-19-2011 09:01 AM In reply to

    Re: Copy LAST row of repeating table?

    I was looking for a similar solution for 2010, with nested repeating tables. I tried both solutions and this one was a homerun. thanks
    Kind regards,
    Larry
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.