[last()] method in Infopath 2010 Repeating Tables Not Working - InfoPath Dev
in

InfoPath Dev

[last()] method in Infopath 2010 Repeating Tables Not Working

Last post 09-05-2011 03:49 AM by Jimmy. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 08-30-2011 09:45 AM

    [last()] method in Infopath 2010 Repeating Tables Not Working

    Hi,

    I have an Infopath 2010 form that run on the client.

     I have a repeating table that I am adding and removing rows using c#. Everything works fine except for the position of the added row. I am using the [last()] method to get the last row and then insert the new row after this using InsertAfter(newRow).

    The problem seems to be that the [last()] method is getting the row that is selected and then adding the new row after this.

    Can anyone tell me how to get a handle on the last row so I an add new rows after this so they appear on the bottom of the repeating table.

     

    Cheers.

  • 08-30-2011 10:21 AM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    It would help if you'd show us what your code actually looks like.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-30-2011 12:27 PM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    Hello,

    I use the following code snippet to add a new row at the bottom of the table...

    XPathNodeIterator currentItem = this.MainDataSource.CreateNavigator().Select("my:myFields/my:group1/my:group2", this.NamespaceManager);

    for (int counter = 0; counter < currentItem.Count; counter++, currentItem.MoveNext()) ;

    currentItem.Current.Clone().InsertAfter(currentItem.Current);

    Hope that helps,

    Regards,

    Karsten
  • 08-30-2011 11:51 PM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    Here is the piece of code I am using

     

    XPathNavigator group = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:InternalSection/my:InternalFloorSection/my:InternalFloorGroup/my:group86/my:group87[last()]", NamespaceManager);XPathNavigator NewRow = group.Clone();

    group.InsertAfter(NewRow);

    If I have a table with 6 rows and the 3rd row is selected and I try to add a new row using this code it will put it after the 3rd row which is selected instead of after the 6th row.

  • 08-31-2011 12:02 AM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    Could you clarify what you mean by "selected?"  I wouldn't think anything like that would have any bearing on this code's behavior.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-31-2011 12:21 AM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    An example would be a repeating table with each row containing a dropdown and a textbox. There are 6 rows in the table.

    I have a button that adds a row to the table using the code above.

    If I select a dropdown in row 3 so that it's background turns blue and then try to add another row the new row will get added after row 3, which had the dropdown selected.

    If I don't select any row that the new row gets added to the bottom as expected.

      It just seams that the [last()] method does not work if a row is selected.

  • 09-05-2011 01:34 AM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    Anyone got any ideas??

  • 09-05-2011 03:49 AM In reply to

    Re: [last()] method in Infopath 2010 Repeating Tables Not Working

    I can't think of any explanation for this behavior and would need to see your form and its code to come any closer to figuring it out.

     So you know, qRules provides an Insert command that accomplishes what you are trying to do here, and uses a more reliable approach (your approach here, copying the last node of the group, will fail if the group is empty).

    I also have a short blog post that describes another alternative:
    http://www.infopathdev.com/blogs/jimmy/archive/2009/03/06/automatically-adding-rows-to-repeating-sections.aspx

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.