Get current row value from an InfoPath repeating table

There will be times that you will find yourself wanting to update a particular value in a repeating table and/or populate details based upon a selected row in a repeating table. This can be done fairly easily by code.

Two of the ways that I accomplished this was either through adding a button to a column in the repeating table or on the “Changed” event of the control in the repeating table. In most of my cases, I had a line number for each row, so I just used that value to reference the row, but if you are wanting to pull certain details from that row, you will need to reference the applicable node.

For the button, btnAdd, click event, it only requires you to call the SelectSingleNode of the XPathNavigator to obtain the value needed in the current row.

   1: public void btnAdd_Clicked(object sender, ClickedEventArgs e)

   2: {

   3:     XPathNavigator DOM = e.Source.CreateNavigator();

   4:     iRow = DOM.SelectSingleNode("my:Item", NamespaceManager).Value;

   5: }


However, if you are trying to obtain the value from the Changed event of a control in a repeating table, it requires a little more code. One thing to note is that you need to check to see if the row is empty before checking for a value, or the call will throw an null reference error. In this example, I’m calling the changed event on a text control and checking to see if the InnerXML is empty. I use the MoveToParent method of the XPathNavigator to access the sibling of the current field in the row of the repeating table.

   1: public void it_totalCost_Changed(object sender, XmlEventArgs e)

   2: {

   3:     XPathNavigator DOM = e.Site.CreateNavigator();

   4:     DOM.MoveToParent();

   5:     if (e.Site.InnerXml != "")

   6:     {

   7:         int row = Convert.ToInt32(DOM.SelectSingleNode("my:it_Item", this.NamespaceManager).InnerXml);

   8:     }

   9: }

*One thing to note, that in the Changed event, the “e” event arg is an XmlEventArgs, which is different then the clicked events (ClickedEventArgs).

Leave a Reply

Your email address will not be published. Required fields are marked *