Appending row to repeating table via code - InfoPath Dev
in

InfoPath Dev

Appending row to repeating table via code

Last post 07-30-2009 07:17 AM by Indyshawn. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-29-2009 07:56 PM

    Appending row to repeating table via code

    I have a nested repeating table that I'm attempting to append rows to via C#. I'm very close to having it working properly, however, the issue I'm trying to resolve is: Each time a new row is appended to the nested repeating table, the new row has the correct values in its field, but the field of the first row is also changed to the same new value. The code uses the Clone() function to duplicate the first node and then attempts to reset the field value of that new node. However, when stepping through the code, I found that the field in the first row of the nested table is being reset as well. I'm on a different PC at the moment, so I can paste the exact code I'm using in a follow up. I just wanted to get this post created as my first action since joining the site tonight. Thanks for any input!

    - - Update - - Code snippet with my understanding of each step (thanks for clarifications if my understanding is incorrect!)

    XPathNavigator Group = e.Source.SelectSingleNode("my:TFLgroup", NamespaceManager) ;    <--  Parent group of the repeating group

    XPathNavigator table = Group.SelectSingleNode("my:assocTFLs", NamespaceManager);   <-- Repeating group

    XPathNavigator newRow = table.Clone();    <-- Cloning first row of repeating group

    newRow.SelectSingleNode("my:TFLname", NamespaceManager).SetValue(_temp);  <--- Value update step; this also changes value of original first row

    Group.AppendChild(newRow);   <-- Appending new row to end of repeating group

  • 07-30-2009 12:10 AM In reply to

    Re: Appending row to repeating table via code

     Most likely the issue is that the Clone() method does not actually clone a node.  It just clones the XPath navigator.  Please check out this post:

    http://www.infopathdev.com/forums/p/11440/40502.aspx#40502

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-30-2009 05:57 AM In reply to

    Re: Appending row to repeating table via code

    Thanks for referring to the previous post - that's exactly the same issue I'm having.  However, I'm not quite understanding the solution that was recommended in the post-reply.  Specifically, the first step - if a node hasn't been copied/cloned, how can it be appended?  I think there's something being implied that I'm not picking up.

  • 07-30-2009 07:17 AM In reply to

    So I think I've got this working now after reviewing a few more posts and doing some trial & error code updates.  I've come to the following code/conclusion (code-clusion?):

    XPathNavigator Group = e.Source.SelectSingleNode("my:TFLgroup", NamespaceManager) ;XPathNavigator table = Group.SelectSingleNode("my:assocTFLs", NamespaceManager);Group.AppendChild(table);   <-- Appends a copy of the first rowXPathNavigator last = Group.SelectSingleNode("child::*[position() = last()]",NamespaceManager);   <-- Reference to the last rowlast.SelectSingleNode("my:TFLname", NamespaceManager).SetValue("New last row value");   <-- Update value of field in the last row

    Even though it's working, I'd be interested in comments re: alternate approaches. 

     Thanks!

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