Autonumbering fields in a repeating table in InfoPath 2007 using VB.NET code
This article shows an example of using the Changed event of the row of a repeating table to programmatically autonumber a field in the repeating table using VB.NET code.
In Programmatically execute code when a repeating table row is inserted or deleted I showed you how you can add an event handler to a repeating table row so that you can execute code when a repeating table row is inserted or deleted.
In this article, I'll give you an example of using the Changed event of the row of a repeating table to programmatically autonumber a field in the repeating table using VB.NET code.
Here are the steps:
- Follow the instructions in Programmatically execute code when a repeating table row is inserted or deleted to add a Changed event handler for the row of a repeating table.
- Add the following code to the Changed event:
Dim nav As XPathNavigator = MainDataSource.CreateNavigator()
Dim iter As XPathNodeIterator = nav.Select("//my:field1", NamespaceManager)
Dim i As Integer = 1
While iter.MoveNext()
iter.Current.SetValue(i.ToString())
i = i + 1
End Whilewhere my:field1 is a field in the repeating table.
The final code would look something like:Public Sub group2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)
Dim nav As XPathNavigator = MainDataSource.CreateNavigator()
Dim iter As XPathNodeIterator = nav.Select("//my:field1", NamespaceManager)
Dim i As Integer = 1
While iter.MoveNext()
iter.Current.SetValue(i.ToString())
i = i + 1
End While
End Sub
Now whenever you insert a row into the repeating table or delete a row from the repeating table, the my:field1 fields in all of the rows of the repeating table are automatically renumbered.
Related InfoPath Articles:
