Add row to repeating table - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Add row to repeating table

Last post 12-18-2008 05:06 AM by GazM. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 12-17-2008 08:53 AM

    Add row to repeating table

    Afternoon everyone

     I hope someone can help me, what I've got is a repeating table with 2 buttons at the top of the screen. the first button shows the table (by default the repeating table is hidden) the second button hides the table and removes all the rows using this vb code:

    Public Sub ButtonMiscExpensesNo_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Retrieve a reference to the Main DOM
    Dim root As XPathNavigator = MainDataSource.CreateNavigator()

    ' Count the amount of group2 nodes
    Dim iter As XPathNodeIterator = root.Select( _
    "/my:myFields/my:MiscExpensesSection/my:MiscExpenseTable/my:MiscEntertainmentExpenses", _
    Dim group2NodesCount As Integer = iter.Count

    ' Retrieve the first group2 node
    Dim firstGroup2NodeNav As XPathNavigator = _
    root.SelectSingleNode("/my:myFields/my:MiscExpensesSection/my:MiscExpenseTable/my:MiscEntertainmentExpenses[1]", _
    ' Retrieve the last group2 node

    Dim lastGroup2NodeNav As XPathNavigator = _
    root.SelectSingleNode("/my:myFields/my:MiscExpensesSection/my:MiscExpenseTable/my:MiscEntertainmentExpenses[" & _
    group2NodesCount.ToString() & "]", _

    ' Delete the range of nodes from the first to the last group2 nodes
    End Sub


    This hides the table once the rows have been deleted. The reason they get deleted is so the fields are fresh incase the user changes his/her mind again and want to use the repeating table. Does anyone know what code I should add (in VB please) to add a row to the table using the button that shows the table? The code below doesn;t work and complains about incorrect data type and no matter what I try it just fails :0(

    Dim myNamespace As String = NamespaceManager.LookupNamespace("my")
    Using writer As XmlWriter = MainDataSource.CreateNavigator().SelectSingleNode( _
    "/my:myFields/my:MiscExpensesSection/my:MiscExpenseTable", NamespaceManager).AppendChild()
    writer.WriteStartElement("MiscEntertainmentExpenses", myNamespace)
    writer.WriteElementString("MiscEntertainmentDate", myNamespace, "")
    writer.WriteElementString("MiscEntertainmentExpense", myNamespace, "")
    writer.WriteElementString("MiscEntertainmentNet", myNamespace, "0")
    End Using

    Any hints or pointers will be appreciated.

    Thanks in advanc



  • 12-17-2008 09:04 AM In reply to

    Re: Add row to repeating table

    You need to access this Manifest file, the following line shows how to get e newRow node 

    XPathNavigator xnNode = this.Template.Manifest.SelectSingleNode("//xsf:xDocumentClass/xsf:views/xsf:view/xsf:editing/xsf:xmlToEdit[@name='NameNodeInManifest']/xsf:editWith/xsf:fragmentToInsert/xsf:chooseFragment/my:RepeatingNode", this.NamespaceManager);

     So first you Save as source file, go to the manifest:xsf en try to find the NameNodeInManifest, This will be the nodename with a number

    After the first part of the code, append the new structure, when you delete the complete range, InfoPath doesn't know the structure anymore

    xnGroupNode.SelectSingleNode("/my:expenseReport/my:MyControls", this.NamespaceManager).AppendChild(xnNode.InnerXml);

    //-- Get the newest appended node --
    xnNewRow = xn.SelectSingleNode("/my:expenseReport/my:MyControls/my:MyControl[last()]", this.NamespaceManager);

    // Add the data to the new row 
    "my:Source", this.NamespaceManager).SetValue("some data")

    Hope this will help you

    Frederik Van Lierde
    Blue InfoPath Blog  ¦  SilverSands Associate  ¦  Do you follow me already?  ¦  We work smart, not hard

    If this article was helpfull, don't forget to rate it, tnx!
  • 12-18-2008 01:27 AM In reply to

    Re: Add row to repeating table


    Thanks for the post but I'm sorry I cant seem to find the NameNodeInManifest string anywhere in the manifest.xsf file. Sorry to be a pain I've only been using Infopath for about 3 months :0(. Also I think that is C# code and in the code editor I have to use VB for some reason?!? Maybe because I dont have VS installed maybe?

    Any pointers would be brilliant :0)

    Thanks again


  • 12-18-2008 05:06 AM In reply to

    • GazM
    • Top 200 Contributor
    • Joined on 11-09-2005
    • England
    • Posts 54

    Re: Add row to repeating table


    Try looking at this forum discussion


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