Programmatically execute code when a repeating table row is inserted or deleted
Learn how to add events to rows of a repeating table instead of its fields.
A technique which I've not often seen explained anywhere on the web is how to use events on the rows of a repeating table instead of its fields.
So in this article I'll tell you how you can add an event to a repeating table so that code can be executed when a repeating table row is either added or deleted. I'll then use this technique in a future post to demonstrate how you can retrieve the number of the current row of a repeating table.
There are two event handlers that you can add to a row of a repeating table:
- Validating Event
- Changed Event
So how do you add an event to a row of a repeating table? Here's how:
- Create a new InfoPath form.
- From the Controls pane, drag-and-drop a Repeating Table on the form. The repeating table will contain 3 columns by default and the rows will be represented by the group2 repeating node of the repeating table.
- From the Data Source pane, right-click the group2 node (this represents the rows), and then select Programming > Changed Event from the context menu that appears. This will add the following VB.NET code for you
Public Sub group2_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)
' Write your code here to change the main data source.
End Sub
Now you can write code in the event handler so that that code is executed when a row is inserted or deleted. You can also add functionality to distinguish between insert and delete operations by testing whether the e.Operation property is equal to XmlOperation.Insert or XmlOperation.Delete.
Related InfoPath Articles:
