How to get the current row number of a repeating table in InfoPath using VB.NET code
This article shows how you can use Visual Basic .NET code in an event handler on the row of a repeating table to automatically number the rows of the repeating table and then retrieve the number of the row in a repeating table in which the value of a field has been changed.
In Programmatically execute code when a repeating table row is inserted or deleted I showed you how to add an event handler to the row of a repeating table. Then in Autonumbering fields in a repeating table in InfoPath 2007 using VB.NET code I showed you how you can write code in the event handler of the row to re-number a field in the repeating table whenever a row is inserted or deleted.
Note that you can also use a formula in InfoPath to autonumber a repeating table instead of writing code.
Now all you have to do to get the number of the row in which a field in the repeating table is being changed, is add a Changed event handler for that field and then write code to retrieve the row number that has been stored in the autonumber field in the same row as that field.
Example: In InfoPath, you have a repeating table with 3 columns. You stored the row numbers in the first field (my:field1) of the repeating table. When you change the value of the second field (my:field2) of the repeating table and then move away from that field, you want to determine the number of the row in which you just made a change.
You can write the following code for the Changed event handler of my:field2 to determine the row number as follows:
Public Sub field2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)
Dim site As XPathNavigator = e.Site
Dim rowNumber As String = site.SelectSingleNode("my:field1", NamespaceManager).Value
Limitation: Because InfoPath does not fire events as data changes are being made, you can only perform a check after data has changed. And the Changed event does not fire if data has not been changed. These are two important things to remember as you design your InfoPath solutions.
Related InfoPath Articles:
- What is InfoPath repeating table
- Autonumber repeating table rows in InfoPath 2010
- How to loop through items in a repeating table in InfoPath 2007
- Programmatically execute code when a repeating table row is inserted or deleted
- SharePoint Designer 2013 workflow to loop through InfoPath repeating table
Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.